annotate src/if_ole.cpp @ 307:7010607c5753

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