ReactOS  0.4.14-dev-98-gb0d4763
vfdshutil.cpp File Reference
#include <windows.h>
#include <objbase.h>
#include <stdio.h>
#include "vfdtypes.h"
#include "vfdapi.h"
#include "vfdlib.h"
#include "vfdshcfact.h"
#include <initguid.h>
#include <shlguid.h>
#include "vfdshguid.h"
Include dependency graph for vfdshutil.cpp:

Go to the source code of this file.

Macros

#define WIN32_LEAN_AND_MEAN
 
#define INITGUID
 
#define REGKEY_APPROVED   "Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"
 

Functions

STDAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
 
STDAPI DllCanUnloadNow (void)
 
static void MakeGuidString (LPTSTR str, const GUID &guid)
 
DWORD WINAPI VfdRegisterHandlers ()
 
DWORD WINAPI VfdUnregisterHandlers ()
 
DWORD WINAPI VfdCheckHandlers ()
 

Macro Definition Documentation

◆ INITGUID

#define INITGUID

Definition at line 28 of file vfdshutil.cpp.

◆ REGKEY_APPROVED

#define REGKEY_APPROVED   "Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"

Definition at line 39 of file vfdshutil.cpp.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 11 of file vfdshutil.cpp.

Function Documentation

◆ DllCanUnloadNow()

STDAPI DllCanUnloadNow ( void  )

Definition at line 76 of file vfdshutil.cpp.

77 {
78  VFDTRACE(0,
79  ("DllCanUnloadNow - %s\n", (g_cDllRefCnt ? "No" : "Yes")));
80 
81  return (g_cDllRefCnt ? S_FALSE : S_OK);
82 }
UINT g_cDllRefCnt
#define S_FALSE
Definition: winerror.h:2357
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define S_OK
Definition: intsafe.h:59

◆ DllGetClassObject()

STDAPI DllGetClassObject ( REFCLSID  rclsid,
REFIID  riid,
LPVOID ppvOut 
)

Definition at line 50 of file vfdshutil.cpp.

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 }
REFIID riid
Definition: precomp.h:44
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:2663
STDMETHODIMP QueryInterface(REFIID, LPVOID *)
Definition: vfdshcfact.cpp:47
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
smooth NULL
Definition: ftsmooth.c:416
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95

◆ MakeGuidString()

static void MakeGuidString ( LPTSTR  str,
const GUID guid 
)
inlinestatic

Definition at line 88 of file vfdshutil.cpp.

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 }
#define sprintf(buf, format,...)
Definition: sprintf.c:55
const GUID * guid
const WCHAR * str

Referenced by VfdCheckHandlers(), VfdRegisterHandlers(), and VfdUnregisterHandlers().

◆ VfdCheckHandlers()

DWORD WINAPI VfdCheckHandlers ( )

Definition at line 393 of file vfdshutil.cpp.

394 {
395  TCHAR buf[MAX_PATH];
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 
415  return ERROR_PATH_NOT_FOUND;
416  }
417 
418  return ERROR_SUCCESS;
419 }
#define ERROR_SUCCESS
Definition: deptool.c:10
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define _stricmp
Definition: cat.c:22
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define VFDEXT_DESCRIPTION
Definition: vfdlib.h:58
char TCHAR
Definition: xmlstorage.h:189
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
int ret
static void MakeGuidString(LPTSTR str, const GUID &guid)
Definition: vfdshutil.cpp:88
static calc_node_t temp
Definition: rpn_ieee.c:38
#define RegQueryValue
Definition: winreg.h:523
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
signed int * PLONG
Definition: retypes.h:5

Referenced by Shell(), and Status().

◆ VfdRegisterHandlers()

DWORD WINAPI VfdRegisterHandlers ( )

Definition at line 100 of file vfdshutil.cpp.

101 {
102  TCHAR buf[MAX_PATH];
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 
125  if (temp == REG_OPENED_EXISTING_KEY) {
126  temp = sizeof(buf);
127 
129  hKey, NULL, NULL, NULL, (PBYTE)buf, &temp);
130 
131  if (ret != ERROR_SUCCESS) {
132  RegCloseKey(hKey);
133  return ret;
134  }
135 
137  RegCloseKey(hKey);
138  return ERROR_FILE_EXISTS;
139  }
140  }
141  else {
142 
143  VFDTRACE(0, ("@=" VFDEXT_DESCRIPTION "\n"));
144 
145  ret = RegSetValueEx(hKey, NULL, NULL, REG_SZ,
147 
148  RegCloseKey(hKey);
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 
164  0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
165 
166  if (ret != ERROR_SUCCESS) {
167  return ret;
168  }
169 
171 
172  VFDTRACE(0, ("@=%s\n", buf));
173 
174  ret = RegSetValueEx(
175  hKey, NULL, NULL, REG_SZ, (PBYTE)buf, temp + 1);
176 
177  if (ret != ERROR_SUCCESS) {
178  RegCloseKey(hKey);
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 
187  RegCloseKey(hKey);
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 
200  0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
201 
202  if (ret != ERROR_SUCCESS) {
203  return ret;
204  }
205 
206  VFDTRACE(0, ("@=%s\n", guid_str));
207 
208  ret = RegSetValueEx(hKey, NULL, NULL, REG_SZ,
209  (PBYTE)guid_str, strlen(guid_str) + 1);
210 
211  RegCloseKey(hKey);
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 
228  0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
229 
230  if (ret != ERROR_SUCCESS) {
231  return ret;
232  }
233 
234  VFDTRACE(0, ("@=%s\n", guid_str));
235 
236  ret = RegSetValueEx(hKey, NULL, NULL, REG_SZ,
237  (PBYTE)guid_str, strlen(guid_str) + 1);
238 
239  RegCloseKey(hKey);
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 
253  0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
254 
255  if (ret != ERROR_SUCCESS) {
256  return ret;
257  }
258 
259  VFDTRACE(0, ("@=%s\n", guid_str));
260 
261  ret = RegSetValueEx(hKey, NULL, NULL, REG_SZ,
262  (PBYTE)guid_str, strlen(guid_str) + 1);
263 
264  RegCloseKey(hKey);
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 
289  RegCloseKey(hKey);
290 
291  return ret;
292 }
#define RegQueryValueEx
Definition: winreg.h:524
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define IS_WINDOWS_NT()
Definition: vfdcmd.c:159
#define ERROR_SUCCESS
Definition: deptool.c:10
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define VFDEXT_PROP_REGKEY
Definition: vfdlib.h:61
#define REGKEY_APPROVED
Definition: vfdshutil.cpp:39
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
#define _stricmp
Definition: cat.c:22
#define sprintf(buf, format,...)
Definition: sprintf.c:55
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define VFDEXT_MENU_REGKEY
Definition: vfdlib.h:59
#define VFDEXT_DND_REGKEY
Definition: vfdlib.h:60
#define VFDEXT_DESCRIPTION
Definition: vfdlib.h:58
char TCHAR
Definition: xmlstorage.h:189
#define MAX_PATH
Definition: compat.h:26
HINSTANCE g_hDllModule
unsigned long DWORD
Definition: ntddk_ex.h:95
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define GetModuleFileName
Definition: winbase.h:3655
int ret
static void MakeGuidString(LPTSTR str, const GUID &guid)
Definition: vfdshutil.cpp:88
static calc_node_t temp
Definition: rpn_ieee.c:38
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
BYTE * PBYTE
Definition: pedump.c:66
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by Shell().

◆ VfdUnregisterHandlers()

DWORD WINAPI VfdUnregisterHandlers ( )

Definition at line 297 of file vfdshutil.cpp.

298 {
299  TCHAR buf[MAX_PATH];
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 
320  return ERROR_PATH_NOT_FOUND;
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 
385  RegCloseKey(hKey);
386 
387  return ret;
388 }
#define IS_WINDOWS_NT()
Definition: vfdcmd.c:159
#define ERROR_SUCCESS
Definition: deptool.c:10
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define VFDEXT_PROP_REGKEY
Definition: vfdlib.h:61
#define REGKEY_APPROVED
Definition: vfdshutil.cpp:39
#define _stricmp
Definition: cat.c:22
#define sprintf(buf, format,...)
Definition: sprintf.c:55
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define VFDEXT_MENU_REGKEY
Definition: vfdlib.h:59
#define VFDEXT_DND_REGKEY
Definition: vfdlib.h:60
#define VFDEXT_DESCRIPTION
Definition: vfdlib.h:58
char TCHAR
Definition: xmlstorage.h:189
#define RegDeleteValue
Definition: winreg.h:508
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
int ret
static void MakeGuidString(LPTSTR str, const GUID &guid)
Definition: vfdshutil.cpp:88
static calc_node_t temp
Definition: rpn_ieee.c:38
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define RegDeleteKey
Definition: winreg.h:502
#define RegQueryValue
Definition: winreg.h:523
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
signed int * PLONG
Definition: retypes.h:5
#define RegCreateKeyEx
Definition: winreg.h:501
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by Shell().