ReactOS 0.4.15-dev-8227-g32d615f
vfdshutil.cpp
Go to the documentation of this file.
1/*
2 vfdshutil.cpp
3
4 Virtual Floppy Drive for Windows
5 Driver control library
6 shell extension utility functions
7
8 Copyright (c) 2003-2005 Ken Kato
9*/
10
11#define WIN32_LEAN_AND_MEAN
12#include <windows.h>
13#include <objbase.h>
14#include <stdio.h>
15
16#include "vfdtypes.h"
17#include "vfdapi.h"
18#include "vfdlib.h"
19#include "vfdshcfact.h"
20
21//=====================================
22// Initialize the GUID instance
23//=====================================
24
25#ifdef _MSC_VER
26#pragma data_seg(".text")
27#endif
28#define INITGUID
29#include <initguid.h>
30#include <shlguid.h>
31#include "vfdshguid.h"
32#ifdef _MSC_VER
33#pragma data_seg()
34#endif
35
36//
37// Registry path to the approved shell extensions key
38//
39#define REGKEY_APPROVED \
40 "Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"
41
42
43//=====================================
44// Shell extension library requirements
45//=====================================
46
47//
48// Creates a class factory instance
49//
51 REFCLSID rclsid,
53 LPVOID *ppvOut)
54{
55 VFDTRACE(0,
56 ("DllGetClassObject\n"));
57
58 *ppvOut = NULL;
59
60 if (IsEqualIID(rclsid, CLSID_VfdShellExt)) {
61 CVfdFactory *pFactory = new CVfdFactory;
62
63 if (!pFactory) {
64 return E_OUTOFMEMORY;
65 }
66
67 return pFactory->QueryInterface(riid, ppvOut);
68 }
69
71}
72
73//
74// DllCanUnloadNow
75//
77{
78 VFDTRACE(0,
79 ("DllCanUnloadNow - %s\n", (g_cDllRefCnt ? "No" : "Yes")));
80
81 return (g_cDllRefCnt ? S_FALSE : S_OK);
82}
83
84//=====================================
85// Shell extension register functions
86//=====================================
87
88static inline void MakeGuidString(LPTSTR str, const GUID &guid)
89{
90 sprintf(str, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
91 guid.Data1, guid.Data2, guid.Data3,
92 guid.Data4[0], guid.Data4[1],
93 guid.Data4[2], guid.Data4[3], guid.Data4[4],
94 guid.Data4[5], guid.Data4[6], guid.Data4[7]);
95}
96
97//
98// Regster this dll as shell extention handlers
99//
101{
103 TCHAR guid_str[40];
104 HKEY hKey;
105 DWORD temp;
106 DWORD ret;
107
108 MakeGuidString(guid_str, CLSID_VfdShellExt);
109
110 //
111 // Register the GUID in the CLSID subtree
112 //
113 sprintf(buf, "CLSID\\%s", guid_str);
114
115 VFDTRACE(0, ("HKCR\\%s\n", buf));
116
119 0, KEY_ALL_ACCESS, NULL, &hKey, &temp);
120
121 if (ret != ERROR_SUCCESS) {
122 return ret;
123 }
124
126 temp = sizeof(buf);
127
129 hKey, NULL, NULL, NULL, (PBYTE)buf, &temp);
130
131 if (ret != ERROR_SUCCESS) {
133 return ret;
134 }
135
138 return ERROR_FILE_EXISTS;
139 }
140 }
141 else {
142
143 VFDTRACE(0, ("@=" VFDEXT_DESCRIPTION "\n"));
144
147
149
150 if (ret != ERROR_SUCCESS) {
151 return ret;
152 }
153 }
154
155 //
156 // Register the executable path
157 //
158 sprintf(buf, "CLSID\\%s\\InProcServer32", guid_str);
159
160 VFDTRACE(0, ("HKCR\\%s\n", buf));
161
165
166 if (ret != ERROR_SUCCESS) {
167 return ret;
168 }
169
171
172 VFDTRACE(0, ("@=%s\n", buf));
173
175 hKey, NULL, NULL, REG_SZ, (PBYTE)buf, temp + 1);
176
177 if (ret != ERROR_SUCCESS) {
179 return ret;
180 }
181
182 VFDTRACE(0, ("ThreadingModel=Apartment\n"));
183
184 ret = RegSetValueEx(hKey, "ThreadingModel", NULL, REG_SZ,
185 (PBYTE)"Apartment", sizeof("Apartment"));
186
188
189 if (ret != ERROR_SUCCESS) {
190 return ret;
191 }
192
193 //
194 // Register context menu handler
195 //
196 VFDTRACE(0, ("HKCR\\" VFDEXT_MENU_REGKEY "\n"));
197
201
202 if (ret != ERROR_SUCCESS) {
203 return ret;
204 }
205
206 VFDTRACE(0, ("@=%s\n", guid_str));
207
209 (PBYTE)guid_str, strlen(guid_str) + 1);
210
212
213 if (ret != ERROR_SUCCESS) {
214 return ret;
215 }
216
217 //
218 // Register Drag&Drop handler
219 //
220 if (!IS_WINDOWS_NT()) {
221 //
222 // Windows NT does not support Drag&Drop handlers ???
223 //
224 VFDTRACE(0, ("HKCR\\" VFDEXT_DND_REGKEY "\n"));
225
229
230 if (ret != ERROR_SUCCESS) {
231 return ret;
232 }
233
234 VFDTRACE(0, ("@=%s\n", guid_str));
235
237 (PBYTE)guid_str, strlen(guid_str) + 1);
238
240
241 if (ret != ERROR_SUCCESS) {
242 return ret;
243 }
244 }
245
246 //
247 // Register property sheet handler
248 //
249 VFDTRACE(0, ("HKCR\\" VFDEXT_PROP_REGKEY "\n"));
250
254
255 if (ret != ERROR_SUCCESS) {
256 return ret;
257 }
258
259 VFDTRACE(0, ("@=%s\n", guid_str));
260
262 (PBYTE)guid_str, strlen(guid_str) + 1);
263
265
266 if (ret != ERROR_SUCCESS) {
267 return ret;
268 }
269
270 //
271 // Register approved extensions entry
272 //
273 VFDTRACE(0, ("HKLM\\" REGKEY_APPROVED "\n"));
274
277 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
278
279 if (ret != ERROR_SUCCESS) {
280 return ret;
281 }
282
283 VFDTRACE(0,
284 ("%s=" VFDEXT_DESCRIPTION "\n", guid_str));
285
286 ret = RegSetValueEx(hKey, guid_str, NULL, REG_SZ,
288
290
291 return ret;
292}
293
294//
295// Unregister context menu handler
296//
298{
300 TCHAR guid_str[40];
301 HKEY hKey;
302 DWORD temp;
303 DWORD ret;
304
305 MakeGuidString(guid_str, CLSID_VfdShellExt);
306
307 sprintf(buf, "CLSID\\%s", guid_str);
308
309 VFDTRACE(0, ("HKCR\\%s\n", buf));
310
311 temp = sizeof(buf);
312
314
315 if (ret != ERROR_SUCCESS) {
316 return ret;
317 }
318
321 }
322
323 sprintf(buf, "CLSID\\%s\\InProcServer32", guid_str);
324
325 VFDTRACE(0, ("HKCR\\%s\n", buf));
326
328
329 if (ret != ERROR_SUCCESS) {
330 return ret;
331 }
332
333 sprintf(buf, "CLSID\\%s", guid_str);
334
335 VFDTRACE(0, ("HKCR\\%s\n", buf));
336
338
339 if (ret != ERROR_SUCCESS) {
340 return ret;
341 }
342
343 VFDTRACE(0, ("HKCR\\" VFDEXT_MENU_REGKEY "\n"));
344
346
347 if (ret != ERROR_SUCCESS) {
348 return ret;
349 }
350
351 if (!IS_WINDOWS_NT()) {
352
353 // Windows NT doesn't support Drag & Drop handlers ???
354
355 VFDTRACE(0, ("HKCR\\" VFDEXT_DND_REGKEY "\n"));
356
358
359 if (ret != ERROR_SUCCESS) {
360 return ret;
361 }
362 }
363
364 VFDTRACE(0, ("HKCR\\" VFDEXT_PROP_REGKEY "\n"));
365
367
368 if (ret != ERROR_SUCCESS) {
369 return ret;
370 }
371
372 VFDTRACE(0, ("HKLM\\" REGKEY_APPROVED "\n"));
373
377 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
378
379 if (ret != ERROR_SUCCESS) {
380 return ret;
381 }
382
383 ret = RegDeleteValue(hKey, guid_str);
384
386
387 return ret;
388}
389
390//
391// Check if context menu handler is registered
392//
394{
396 TCHAR guid_str[40];
397 DWORD temp;
398 DWORD ret;
399
400 MakeGuidString(guid_str, CLSID_VfdShellExt);
401
402 sprintf(buf, "CLSID\\%s", guid_str);
403
404 VFDTRACE(0, ("HKCR\\%s\n", buf));
405
406 temp = sizeof(buf);
407
409
410 if (ret != ERROR_SUCCESS) {
411 return ret;
412 }
413
416 }
417
418 return ERROR_SUCCESS;
419}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define STDAPI
Definition: basetyps.h:41
#define RegCloseKey(hKey)
Definition: registry.h:49
#define _stricmp
Definition: cat.c:22
STDMETHODIMP QueryInterface(REFIID, LPVOID *)
Definition: vfdshcfact.cpp:47
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define REG_SZ
Definition: layer.c:22
const GUID * guid
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
BYTE * PBYTE
Definition: pedump.c:66
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
const WCHAR * str
static calc_node_t temp
Definition: rpn_ieee.c:38
int32_t * PLONG
Definition: typedefs.h:58
#define IS_WINDOWS_NT()
Definition: vfdcmd.c:159
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
UINT g_cDllRefCnt
HINSTANCE g_hDllModule
#define VFDEXT_MENU_REGKEY
Definition: vfdlib.h:59
#define VFDEXT_DESCRIPTION
Definition: vfdlib.h:58
#define VFDEXT_PROP_REGKEY
Definition: vfdlib.h:61
#define VFDEXT_DND_REGKEY
Definition: vfdlib.h:60
DWORD WINAPI VfdCheckHandlers()
Definition: vfdshutil.cpp:393
#define REGKEY_APPROVED
Definition: vfdshutil.cpp:39
static void MakeGuidString(LPTSTR str, const GUID &guid)
Definition: vfdshutil.cpp:88
DWORD WINAPI VfdUnregisterHandlers()
Definition: vfdshutil.cpp:297
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
Definition: vfdshutil.cpp:50
STDAPI DllCanUnloadNow(void)
Definition: vfdshutil.cpp:76
DWORD WINAPI VfdRegisterHandlers()
Definition: vfdshutil.cpp:100
int ret
#define GetModuleFileName
Definition: winbase.h:3831
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:2663
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define RegQueryValueEx
Definition: winreg.h:524
#define RegDeleteKey
Definition: winreg.h:502
#define RegDeleteValue
Definition: winreg.h:508
#define RegQueryValue
Definition: winreg.h:523
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192