annotate src/if_ole.cpp @ 49:000769ce6c9d default tip

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