annotate src/if_ole.cpp @ 34347:3cbe1e26d561 v9.1.0106

patch 9.1.0106: Visual highlight hard to read with 'termguicolors' Commit: https://github.com/vim/vim/commit/34e4a05d02a016fe230495be8f6c60ddd56f9567 Author: Maxim Kim <habamax@gmail.com> Date: Wed Feb 14 20:28:17 2024 +0100 patch 9.1.0106: Visual highlight hard to read with 'termguicolors' Problem: Visual highlight hard to read with 'termguicolors' (Maxim Kim) Solution: Set Visual GUI foreground to black (with background=light) and lightgrey (with background=dark) (Maxim Kim) fixes: #14024 closes: #14025 Signed-off-by: Maxim Kim <habamax@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Wed, 14 Feb 2024 20:45:04 +0100
parents 161ae1985d81
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 8641
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8
15886
cdb9cbe731b3 patch 8.1.0949: MS-windows defines GUI macros different than other systems
Bram Moolenaar <Bram@vim.org>
parents: 15868
diff changeset
9 #if defined(FEAT_OLE) && defined(FEAT_GUI_MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * OLE server implementation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * See os_mswin.c for the client side.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 */
919
3cd88bdcd97d updated for version 7.0-045
vimboss
parents: 859
diff changeset
15 extern "C" {
931
c5871806d7e6 updated for version 7.0-057
vimboss
parents: 919
diff changeset
16 # include "vim.h"
919
3cd88bdcd97d updated for version 7.0-045
vimboss
parents: 859
diff changeset
17 }
3cd88bdcd97d updated for version 7.0-045
vimboss
parents: 859
diff changeset
18
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 #include <windows.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #include <oleauto.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 extern "C" {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 extern HWND s_hwnd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 extern HWND vim_parent_hwnd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
8641
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8299
diff changeset
27 #if (defined(_MSC_VER) && (_MSC_VER >= 1700)) || (__cplusplus >= 201103L)
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8299
diff changeset
28 # define FINAL final
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8299
diff changeset
29 #else
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8299
diff changeset
30 # define FINAL
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8299
diff changeset
31 #endif
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8299
diff changeset
32
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 #include "if_ole.h" // Interface definitions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 #include "iid_ole.c" // UUID definitions (compile here)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 /* Supply function prototype to work around bug in Mingw oleauto.h header */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 #ifdef __MINGW32__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 WINOLEAUTAPI UnRegisterTypeLib(REFGUID libID, WORD wVerMajor,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 WORD wVerMinor, LCID lcid, SYSKIND syskind);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 /*****************************************************************************
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 1. Internal definitions for this file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 *****************************************************************************/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 class CVim;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 class CVimCF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 /* Internal data */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 // The identifier of the registered class factory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 static unsigned long cf_id = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 // The identifier of the running application object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 static unsigned long app_id = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 // The single global instance of the class factory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 static CVimCF *cf = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 // The single global instance of the application object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 static CVim *app = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 /* GUIDs, versions and type library information */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 #define MYCLSID CLSID_Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 #define MYLIBID LIBID_Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 #define MYIID IID_IVim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 #define MAJORVER 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 #define MINORVER 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 #define LOCALE 0x0409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 #define MYNAME "Vim"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 #define MYPROGID "Vim.Application.1"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 #define MYVIPROGID "Vim.Application"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 #define MAX_CLSID_LEN 100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 /*****************************************************************************
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 2. The application object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 *****************************************************************************/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 /* Definition
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 * ----------
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
8641
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8299
diff changeset
85 class CVim FINAL : public IVim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 public:
8299
d2a215e8d5b4 commit https://github.com/vim/vim/commit/e0fd2aa8f6544f9cf8286c707be3fb1c66c609e6
Christian Brabandt <cb@256bit.org>
parents: 4352
diff changeset
88 virtual ~CVim();
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
89 static CVim *Create(int *pbDoRestart);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 // IUnknown members
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 STDMETHOD(QueryInterface)(REFIID riid, void ** ppv);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 STDMETHOD_(unsigned long, AddRef)(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 STDMETHOD_(unsigned long, Release)(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 // IDispatch members
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 STDMETHOD(GetTypeInfoCount)(UINT *pCount);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 STDMETHOD(GetTypeInfo)(UINT iTypeInfo, LCID, ITypeInfo **ppITypeInfo);
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
99 STDMETHOD(GetIDsOfNames)(const IID &iid, OLECHAR **names, UINT n, LCID, DISPID *dispids);
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
100 STDMETHOD(Invoke)(DISPID member, const IID &iid, LCID, WORD flags, DISPPARAMS *dispparams, VARIANT *result, EXCEPINFO *excepinfo, UINT *argerr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 // IVim members
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 STDMETHOD(SendKeys)(BSTR keys);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 STDMETHOD(Eval)(BSTR expr, BSTR *result);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 STDMETHOD(SetForeground)(void);
1569
9fbb40a1228a updated for version 7.1-282
vimboss
parents: 931
diff changeset
106 STDMETHOD(GetHwnd)(UINT_PTR *result);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 private:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 // Constructor is private - create using CVim::Create()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 CVim() : ref(0), typeinfo(0) {};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 // Reference count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 unsigned long ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 // The object's TypeInfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 ITypeInfo *typeinfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 /* Implementation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 * --------------
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
123 CVim *CVim::Create(int *pbDoRestart)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 HRESULT hr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 CVim *me = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 ITypeLib *typelib = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 ITypeInfo *typeinfo = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 *pbDoRestart = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 // Create the object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 me = new CVim();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 if (me == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 MessageBox(0, "Cannot create application object", "Vim Initialisation", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 // Load the type library from the registry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 hr = LoadRegTypeLib(MYLIBID, 1, 0, 0x00, &typelib);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 if (FAILED(hr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 HKEY hKey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 // Check we can write to the registry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 // RegCreateKeyEx succeeds even if key exists. W.Briscoe W2K 20021011
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 if (RegCreateKeyEx(HKEY_CLASSES_ROOT, MYVIPROGID, 0, NULL,
2443
499bff609a86 Possibly make OLE work on Windows 64 bit. (untested)
Bram Moolenaar <bram@vim.org>
parents: 2224
diff changeset
149 REG_OPTION_NON_VOLATILE,
2474
a29301e7c05f Take OLE registration back to 32 bit registry, the unregister wasn't working
Bram Moolenaar <bram@vim.org>
parents: 2469
diff changeset
150 KEY_ALL_ACCESS, NULL, &hKey, NULL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 delete me;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 return NULL; // Unable to write to registry. Quietly fail.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 RegCloseKey(hKey);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 if (MessageBox(0, "Cannot load registered type library.\nDo you want to register Vim now?",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 "Vim Initialisation", MB_YESNO | MB_ICONQUESTION) != IDYES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 delete me;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 RegisterMe(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 // Load the type library from the registry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 hr = LoadRegTypeLib(MYLIBID, 1, 0, 0x00, &typelib);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 if (FAILED(hr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 MessageBox(0, "You must restart Vim in order for the registration to take effect.",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 "Vim Initialisation", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 *pbDoRestart = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 delete me;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 // Get the type info of the vtable interface
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 hr = typelib->GetTypeInfoOfGuid(MYIID, &typeinfo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 typelib->Release();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 if (FAILED(hr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 MessageBox(0, "Cannot get interface type information",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 "Vim Initialisation", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 delete me;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 // Save the type information
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 me->typeinfo = typeinfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 return me;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 CVim::~CVim()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 if (typeinfo && vim_parent_hwnd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 typeinfo->Release();
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
199 typeinfo = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 CVim::QueryInterface(REFIID riid, void **ppv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IDispatch) || IsEqualIID(riid, MYIID))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 AddRef();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 *ppv = this;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 *ppv = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 return E_NOINTERFACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 STDMETHODIMP_(ULONG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 CVim::AddRef()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 return ++ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 STDMETHODIMP_(ULONG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 CVim::Release()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 // Don't delete the object when the reference count reaches zero, as there
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 // is only a single application object, and its lifetime is controlled by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 // the running instance, not by its reference count.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 if (ref > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 --ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 return ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 CVim::GetTypeInfoCount(UINT *pCount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 *pCount = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 CVim::GetTypeInfo(UINT iTypeInfo, LCID, ITypeInfo **ppITypeInfo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 *ppITypeInfo = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 if (iTypeInfo != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 return DISP_E_BADINDEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 typeinfo->AddRef();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 *ppITypeInfo = typeinfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 CVim::GetIDsOfNames(
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
255 const IID &iid,
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
256 OLECHAR **names,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 UINT n,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 LCID,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 DISPID *dispids)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 if (iid != IID_NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 return DISP_E_UNKNOWNINTERFACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 return typeinfo->GetIDsOfNames(names, n, dispids);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 CVim::Invoke(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 DISPID member,
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
270 const IID &iid,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 LCID,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 WORD flags,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 DISPPARAMS *dispparams,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 VARIANT *result,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 EXCEPINFO *excepinfo,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 UINT *argerr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 if (iid != IID_NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 return DISP_E_UNKNOWNINTERFACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 ::SetErrorInfo(0, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 return typeinfo->Invoke(static_cast<IDispatch*>(this),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 member, flags, dispparams,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 result, excepinfo, argerr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 STDMETHODIMP
1569
9fbb40a1228a updated for version 7.1-282
vimboss
parents: 931
diff changeset
288 CVim::GetHwnd(UINT_PTR *result)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 {
1569
9fbb40a1228a updated for version 7.1-282
vimboss
parents: 931
diff changeset
290 *result = (UINT_PTR)s_hwnd;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 CVim::SetForeground(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 /* Make the Vim window come to the foreground */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 gui_mch_set_foreground();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 CVim::SendKeys(BSTR keys)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 char *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 /* Get a suitable buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 len = WideCharToMultiByte(CP_ACP, 0, keys, -1, 0, 0, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 buffer = (char *)alloc(len+1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 if (buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 return E_OUTOFMEMORY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 len = WideCharToMultiByte(CP_ACP, 0, keys, -1, buffer, len, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 vim_free(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 return E_INVALIDARG;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 /* Translate key codes like <Esc> */
32736
161ae1985d81 patch 9.0.1687: mapset() not properly handling script ID
Christian Brabandt <cb@256bit.org>
parents: 32244
diff changeset
326 str = replace_termcodes((char_u *)buffer, &ptr, 0, REPTERM_DO_LT, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 /* If ptr was set, then a new buffer was allocated,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 * so we can free the old one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 if (ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 vim_free((char_u *)(buffer));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 /* Reject strings too long to fit in the input buffer. Allow 10 bytes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 * space to cover for the (remote) possibility that characters may enter
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 * the input buffer between now and when the WM_OLE message is actually
32244
533e36e02a68 patch 9.0.1453: typos in source code and tests
Bram Moolenaar <Bram@vim.org>
parents: 30598
diff changeset
337 * processed. If more than 10 characters enter the input buffer in that
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 * time, the WM_OLE processing will simply fail to insert the characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 if ((int)(STRLEN(str)) > (vim_free_in_input_buf() - 10))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 return E_INVALIDARG;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 /* Pass the string to the main input loop. The memory will be freed when
1791
5e225f973b5d updated for version 7.2-089
vimboss
parents: 1569
diff changeset
347 * the message is processed. Except for an empty message, we don't need
5e225f973b5d updated for version 7.2-089
vimboss
parents: 1569
diff changeset
348 * to post it then.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 */
1791
5e225f973b5d updated for version 7.2-089
vimboss
parents: 1569
diff changeset
350 if (*str == NUL)
5e225f973b5d updated for version 7.2-089
vimboss
parents: 1569
diff changeset
351 vim_free(str);
5e225f973b5d updated for version 7.2-089
vimboss
parents: 1569
diff changeset
352 else
5e225f973b5d updated for version 7.2-089
vimboss
parents: 1569
diff changeset
353 PostMessage(NULL, WM_OLE, 0, (LPARAM)str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 CVim::Eval(BSTR expr, BSTR *result)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 char *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 char *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 wchar_t *w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 /* Get a suitable buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 len = WideCharToMultiByte(CP_ACP, 0, expr, -1, 0, 0, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 return E_INVALIDARG;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371
16782
fc58fee685e2 patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
372 buffer = (char *)alloc(len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 if (buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 return E_OUTOFMEMORY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 /* Convert the (wide character) expression to an ASCII string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 len = WideCharToMultiByte(CP_ACP, 0, expr, -1, buffer, len, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 return E_INVALIDARG;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 /* Evaluate the expression */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 ++emsg_skip;
30598
37aa9fd2ed72 patch 9.0.0634: evaluating "expr" options has more overhead than needed
Bram Moolenaar <Bram@vim.org>
parents: 27342
diff changeset
384 str = (char *)eval_to_string((char_u *)buffer, TRUE, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 --emsg_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 vim_free(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 if (str == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 return E_FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 /* Convert the result to wide characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 MultiByteToWideChar_alloc(CP_ACP, 0, str, -1, &w_buffer, &len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 if (w_buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 return E_OUTOFMEMORY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 vim_free(w_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 return E_FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 /* Store the result */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 *result = SysAllocString(w_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 vim_free(w_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 return E_NOTIMPL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 /*****************************************************************************
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 3. The class factory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 *****************************************************************************/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 /* Definition
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 * ----------
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419
8641
0af716a4f5d2 commit https://github.com/vim/vim/commit/cc6cf9b9f9045a7d8b5923ea0c556e9a4c2567d3
Christian Brabandt <cb@256bit.org>
parents: 8299
diff changeset
420 class CVimCF FINAL : public IClassFactory
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 public:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 static CVimCF *Create();
8299
d2a215e8d5b4 commit https://github.com/vim/vim/commit/e0fd2aa8f6544f9cf8286c707be3fb1c66c609e6
Christian Brabandt <cb@256bit.org>
parents: 4352
diff changeset
424 virtual ~CVimCF() {};
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 STDMETHOD(QueryInterface)(REFIID riid, void ** ppv);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 STDMETHOD_(unsigned long, AddRef)(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 STDMETHOD_(unsigned long, Release)(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 STDMETHOD(CreateInstance)(IUnknown *punkOuter, REFIID riid, void ** ppv);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 STDMETHOD(LockServer)(BOOL lock);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 private:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 // Constructor is private - create via Create()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 CVimCF() : ref(0) {};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 // Reference count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 unsigned long ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 /* Implementation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 * --------------
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 CVimCF *CVimCF::Create()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 CVimCF *me = new CVimCF();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 if (me == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 MessageBox(0, "Cannot create class factory", "Vim Initialisation", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 return me;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 CVimCF::QueryInterface(REFIID riid, void **ppv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 AddRef();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 *ppv = this;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 *ppv = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 return E_NOINTERFACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 STDMETHODIMP_(ULONG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 CVimCF::AddRef()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 return ++ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 STDMETHODIMP_(ULONG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 CVimCF::Release()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 // Don't delete the object when the reference count reaches zero, as there
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 // is only a single application object, and its lifetime is controlled by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 // the running instance, not by its reference count.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 if (ref > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 --ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 return ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484
322
a18bd33b8ea9 updated for version 7.0084
vimboss
parents: 7
diff changeset
485 /*ARGSUSED*/
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 CVimCF::CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 return app->QueryInterface(riid, ppv);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491
322
a18bd33b8ea9 updated for version 7.0084
vimboss
parents: 7
diff changeset
492 /*ARGSUSED*/
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 STDMETHODIMP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 CVimCF::LockServer(BOOL lock)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 /*****************************************************************************
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 4. Registry manipulation code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 *****************************************************************************/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 // Internal use only
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
504 static void SetKeyAndValue(const char *path, const char *subkey, const char *value);
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
505 static void GUIDtochar(const GUID &guid, char *GUID, int length);
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
506 static void RecursiveDeleteKey(HKEY hKeyParent, const char *child);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 static const int GUID_STRING_SIZE = 39;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 // Register the component in the registry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 // When "silent" is TRUE don't give any messages.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 extern "C" void RegisterMe(int silent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 BOOL ok = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 // Get the application startup command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 char module[MAX_PATH];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 ::GetModuleFileName(NULL, module, MAX_PATH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 // Unregister first (quietly)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 UnregisterMe(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 // Convert the CLSID into a char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 char clsid[GUID_STRING_SIZE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 GUIDtochar(MYCLSID, clsid, sizeof(clsid));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 // Convert the LIBID into a char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 char libid[GUID_STRING_SIZE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 GUIDtochar(MYLIBID, libid, sizeof(libid));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 // Build the key CLSID\\{...}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 char Key[MAX_CLSID_LEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 strcpy(Key, "CLSID\\");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 strcat(Key, clsid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 // Add the CLSID to the registry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 SetKeyAndValue(Key, NULL, MYNAME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 SetKeyAndValue(Key, "LocalServer32", module);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 SetKeyAndValue(Key, "ProgID", MYPROGID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 SetKeyAndValue(Key, "VersionIndependentProgID", MYVIPROGID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 SetKeyAndValue(Key, "TypeLib", libid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 // Add the version-independent ProgID subkey under HKEY_CLASSES_ROOT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 SetKeyAndValue(MYVIPROGID, NULL, MYNAME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 SetKeyAndValue(MYVIPROGID, "CLSID", clsid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 SetKeyAndValue(MYVIPROGID, "CurVer", MYPROGID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 // Add the versioned ProgID subkey under HKEY_CLASSES_ROOT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 SetKeyAndValue(MYPROGID, NULL, MYNAME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 SetKeyAndValue(MYPROGID, "CLSID", clsid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 wchar_t w_module[MAX_PATH];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 MultiByteToWideChar(CP_ACP, 0, module, -1, w_module, MAX_PATH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 ITypeLib *typelib = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 if (LoadTypeLib(w_module, &typelib) != S_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 if (!silent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 MessageBox(0, "Cannot load type library to register",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 "Vim Registration", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 ok = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 if (RegisterTypeLib(typelib, w_module, NULL) != S_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 if (!silent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 MessageBox(0, "Cannot register type library",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 "Vim Registration", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 ok = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 typelib->Release();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 if (ok && !silent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 MessageBox(0, "Registered successfully", "Vim", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 // Remove the component from the registry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 //
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 // Note: There is little error checking in this code, to allow incomplete
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 // or failed registrations to be undone.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 extern "C" void UnregisterMe(int bNotifyUser)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 // Unregister the type library
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 ITypeLib *typelib;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 if (SUCCEEDED(LoadRegTypeLib(MYLIBID, MAJORVER, MINORVER, LOCALE, &typelib)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 TLIBATTR *tla;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 if (SUCCEEDED(typelib->GetLibAttr(&tla)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 UnRegisterTypeLib(tla->guid, tla->wMajorVerNum, tla->wMinorVerNum,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 tla->lcid, tla->syskind);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 typelib->ReleaseTLibAttr(tla);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 typelib->Release();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 // Convert the CLSID into a char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 char clsid[GUID_STRING_SIZE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 GUIDtochar(MYCLSID, clsid, sizeof(clsid));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 // Build the key CLSID\\{...}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 char Key[MAX_CLSID_LEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 strcpy(Key, "CLSID\\");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 strcat(Key, clsid);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 // Delete the CLSID Key - CLSID\{...}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 RecursiveDeleteKey(HKEY_CLASSES_ROOT, Key);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 // Delete the version-independent ProgID Key
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 RecursiveDeleteKey(HKEY_CLASSES_ROOT, MYVIPROGID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 // Delete the ProgID key
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 RecursiveDeleteKey(HKEY_CLASSES_ROOT, MYPROGID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 if (bNotifyUser)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 MessageBox(0, "Unregistered successfully", "Vim", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 /****************************************************************************/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 // Convert a GUID to a char string
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
625 static void GUIDtochar(const GUID &guid, char *GUID, int length)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 // Get wide string version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 LPOLESTR wGUID = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 StringFromCLSID(guid, &wGUID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 20996
diff changeset
631 // Convert from wide characters to non-wide
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 wcstombs(GUID, wGUID, length);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 // Free memory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 CoTaskMemFree(wGUID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 2474
diff changeset
638 // Delete a key and all of its descendants
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
639 static void RecursiveDeleteKey(HKEY hKeyParent, const char *child)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 // Open the child
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 HKEY hKeyChild;
2449
943280505f72 Fix that uninstaller isn't found on 64-bit Windows.
Bram Moolenaar <bram@vim.org>
parents: 2443
diff changeset
643 LONG result = RegOpenKeyEx(hKeyParent, child, 0,
2474
a29301e7c05f Take OLE registration back to 32 bit registry, the unregister wasn't working
Bram Moolenaar <bram@vim.org>
parents: 2469
diff changeset
644 KEY_ALL_ACCESS, &hKeyChild);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 if (result != ERROR_SUCCESS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 2474
diff changeset
648 // Enumerate all of the descendants of this child
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 FILETIME time;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 char buffer[1024];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 DWORD size = 1024;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 while (RegEnumKeyEx(hKeyChild, 0, buffer, &size, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 NULL, NULL, &time) == S_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 {
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 2474
diff changeset
656 // Delete the descendants of this child
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 RecursiveDeleteKey(hKeyChild, buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 size = 256;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 // Close the child
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 RegCloseKey(hKeyChild);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 // Delete this child
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 RegDeleteKey(hKeyParent, child);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 // Create a key and set its value
388
f92bb1845823 updated for version 7.0101
vimboss
parents: 380
diff changeset
669 static void SetKeyAndValue(const char *key, const char *subkey, const char *value)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 HKEY hKey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 char buffer[1024];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 strcpy(buffer, key);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 // Add subkey name to buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 if (subkey)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 strcat(buffer, "\\");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 strcat(buffer, subkey);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 // Create and open key and subkey.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 long result = RegCreateKeyEx(HKEY_CLASSES_ROOT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 buffer,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 0, NULL, REG_OPTION_NON_VOLATILE,
2474
a29301e7c05f Take OLE registration back to 32 bit registry, the unregister wasn't working
Bram Moolenaar <bram@vim.org>
parents: 2469
diff changeset
687 KEY_ALL_ACCESS, NULL,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 &hKey, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 if (result != ERROR_SUCCESS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 // Set the value
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 if (value)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE *)value,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 (DWORD)STRLEN(value)+1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 RegCloseKey(hKey);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 /*****************************************************************************
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 5. OLE Initialisation and shutdown processing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 *****************************************************************************/
380
da6e29ecd0fc updated for version 7.0099
vimboss
parents: 322
diff changeset
703 extern "C" void InitOLE(int *pbDoRestart)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 HRESULT hr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 *pbDoRestart = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 // Initialize the OLE libraries
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 hr = OleInitialize(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 if (FAILED(hr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 MessageBox(0, "Cannot initialise OLE", "Vim Initialisation", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 goto error0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 // Create the application object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 app = CVim::Create(pbDoRestart);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 if (app == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 goto error1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 // Create the class factory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 cf = CVimCF::Create();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 if (cf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 goto error1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 // Register the class factory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 hr = CoRegisterClassObject(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 MYCLSID,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 cf,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 CLSCTX_LOCAL_SERVER,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 REGCLS_MULTIPLEUSE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 &cf_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 if (FAILED(hr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 MessageBox(0, "Cannot register class factory", "Vim Initialisation", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 goto error1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 // Register the application object as active
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 hr = RegisterActiveObject(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 app,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 MYCLSID,
14325
89dd0ad361fb patch 8.1.0178: warning for passing pointer to non-pointer argument
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
745 0,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 &app_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 if (FAILED(hr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 MessageBox(0, "Cannot register application object", "Vim Initialisation", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 goto error1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 // Errors: tidy up as much as needed and return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 error1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 UninitOLE();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 error0:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 extern "C" void UninitOLE()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 // Unregister the application object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 if (app_id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 RevokeActiveObject(app_id, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 app_id = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 // Unregister the class factory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 if (cf_id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 CoRevokeClassObject(cf_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 cf_id = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 // Shut down the OLE libraries
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 OleUninitialize();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 // Delete the application object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 if (app)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 delete app;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 app = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 // Delete the class factory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 if (cf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 delete cf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 cf = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 #endif /* FEAT_OLE */