ReactOS  0.4.13-dev-73-gcfe54aa
misc.cpp
Go to the documentation of this file.
1 /*
2  * ReactOS Explorer
3  *
4  * Copyright 2014 Giannis Adamopoulos
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 
22 #include <stdio.h>
23 #include <tchar.h>
24 
25 #define WIN32_NO_STATUS
26 #define _INC_WINDOWS
27 #define COM_NO_WINDOWS_H
28 
29 #define COBJMACROS
30 
31 #include <windef.h>
32 #include <winbase.h>
33 #include <winreg.h>
34 #include <wingdi.h>
35 #include <winnls.h>
36 #include <wincon.h>
37 #include <shellapi.h>
38 #include <shlobj.h>
39 #include <shlobj_undoc.h>
40 #include <shlwapi.h>
41 #include <shlguid_undoc.h>
42 #include <uxtheme.h>
43 #include <strsafe.h>
44 
45 #include <atlbase.h>
46 #include <atlcom.h>
47 #include <atlwin.h>
48 #include <undocshell.h>
49 #include <undocuser.h>
50 
51 #include <shellutils.h>
52 
53 #include <CQuickLaunchBand.h>
54 
55 #include <wine/debug.h>
56 
57 extern "C"
58 {
60 
66 }
67 
69 {
70  /* do something here (perhaps we may want to add our own implementation fo win8) */
71  return 0;
72 }
73 
74 class CRShellModule : public CComModule
75 {
76 public:
77 };
78 
80 CAtlWinModule gWinModule;
81 
83 
84 static LSTATUS inline _RegSetStringValueW(HKEY hKey, LPCWSTR lpValueName, LPCWSTR lpStringData)
85 {
86  DWORD dwStringDataLen = lstrlenW(lpStringData);
87 
88  return RegSetValueExW(hKey, lpValueName, 0, REG_SZ, (BYTE *) lpStringData, 2 * (dwStringDataLen + 1));
89 }
90 
92 {
93  WCHAR szFilename[MAX_PATH];
94  WCHAR szClsid[MAX_PATH];
95  WCHAR szRoot[MAX_PATH];
96 
97  if (!StringFromGUID2(clsid, szClsid, _countof(szClsid)))
98  return E_FAIL;
99 
100  if (!GetModuleFileNameW(shell32_hInstance, szFilename, _countof(szFilename)))
101  return E_FAIL;
102 
103  HRESULT hr = StringCchPrintfW(szRoot, 0x104u, L"CLSID\\%s", szClsid);
104  if (FAILED(hr))
105  return hr;
106 
107  DWORD dwDisposition;
108  HKEY hkRoot;
109  if (RegCreateKeyExW(HKEY_CLASSES_ROOT, szRoot, 0, NULL, 0, KEY_WRITE, 0, &hkRoot, &dwDisposition) != 0)
110  return E_FAIL;
111 
112  HKEY hkServer;
113 
114  _RegSetStringValueW(hkRoot, NULL, szDisplayName);
115 
116  if (RegCreateKeyExW(hkRoot, L"InprocServer32", 0, NULL, 0, KEY_SET_VALUE, 0, &hkServer, &dwDisposition) != 0)
117  {
118  RegCloseKey(hkRoot);
119  return E_FAIL;
120  }
121 
122  _RegSetStringValueW(hkServer, NULL, szFilename);
123  _RegSetStringValueW(hkServer, L"ThreadingModel", L"Both");
124 
125  RegCloseKey(hkServer);
126  RegCloseKey(hkRoot);
127  return S_OK;
128 }
129 
131 {
132  WCHAR szClsid[MAX_PATH];
133  WCHAR szRoot[MAX_PATH];
134  HKEY hkRoot;
135 
136  if (!StringFromGUID2(clsid, szClsid, _countof(szClsid)))
137  return E_FAIL;
138 
139  HRESULT hr = StringCchPrintfW(szRoot, 0x104u, L"CLSID\\%s", szClsid);
140  if (FAILED(hr))
141  return hr;
142 
143  if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szRoot, 0, KEY_WRITE, &hkRoot) != 0)
144  return E_FAIL;
145 
146  RegDeleteKeyW(hkRoot, L"InprocServer32");
147  RegCloseKey(hkRoot);
148 
150 
151  return S_OK;
152 }
153 
155 {
157  {
159 
160  gModule.Init(NULL, hInstance, NULL);
162  }
163  else if (dwReason == DLL_PROCESS_DETACH)
164  {
166  gModule.Term();
167  }
168  return TRUE;
169 }
170 
171 HRESULT
172 WINAPI
174 {
175  gModule.DllCanUnloadNow();
176  return S_FALSE;
177 }
178 
179 STDAPI
181 {
182 #if 0
183  RegisterComponent(CLSID_StartMenu, L"Shell Start Menu");
184  RegisterComponent(CLSID_MenuDeskBar, L"Shell Menu Desk Bar");
185  RegisterComponent(CLSID_MenuBand, L"Shell Menu Band");
186  RegisterComponent(CLSID_MenuBandSite, L"Shell Menu Band Site");
187  RegisterComponent(CLSID_MergedFolder, L"Merged Shell Folder");
188  RegisterComponent(CLSID_RebarBandSite, L"Shell Rebar Band Site");
189 #endif
190  RegisterComponent(CLSID_QuickLaunchBand, L"Quick Launch");
191  RegisterComCat();
192  return S_OK;
193 }
194 
195 STDAPI
197 {
198 #if 0
200  UnregisterComponent(CLSID_MenuDeskBar);
201  UnregisterComponent(CLSID_MenuBand);
203  UnregisterComponent(CLSID_MergedFolder);
204  UnregisterComponent(CLSID_RebarBandSite);
205 #endif
208  return S_OK;
209 }
210 
212  public CComObjectRootEx<CComMultiThreadModelNoCS>,
213  public IClassFactory
214 {
215 private:
217 
218 public:
220  virtual ~CRShellClassFactory() {}
221 
223  {
224  m_Clsid = clsid;
225  return S_OK;
226  }
227 
228  /* IClassFactory */
230  {
231  *ppvObject = NULL;
232 
235 
236  if (IsEqualCLSID(m_Clsid, CLSID_MenuDeskBar))
238 
239  if (IsEqualCLSID(m_Clsid, CLSID_MenuBand))
241 
244 
245  if (IsEqualCLSID(m_Clsid, CLSID_MergedFolder))
247 
249  return ShellObjectCreator<CQuickLaunchBand>(riid, ppvObject);
250 
251  return E_NOINTERFACE;
252  }
253 
254  virtual HRESULT WINAPI LockServer(BOOL fLock)
255  {
256  return E_NOTIMPL;
257  }
258 
261  END_COM_MAP()
262 };
263 
264 STDAPI
266 REFCLSID rclsid,
267 REFIID riid,
268 LPVOID *ppv)
269 {
270  if (!ppv)
271  return E_INVALIDARG;
272 
273  *ppv = NULL;
274 
275  return ShellObjectCreatorInit<CRShellClassFactory>(rclsid, riid, ppv);
276 }
virtual ~CRShellClassFactory()
Definition: misc.cpp:220
#define STDAPI
Definition: basetyps.h:41
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:607
#define REFIID
Definition: guiddef.h:113
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
HRESULT hr
Definition: shlfolder.c:183
#define KEY_SET_VALUE
Definition: nt_native.h:1017
Definition: scsiwmi.h:51
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
REFIID riid
Definition: precomp.h:44
#define REFCLSID
Definition: guiddef.h:112
#define _countof(array)
Definition: fontsub.cpp:30
HRESULT WINAPI RSHELL_CMenuBand_CreateInstance(REFIID riid, LPVOID *ppv)
Definition: CMenuBand.cpp:1313
HRESULT Initialize(REFGUID clsid)
Definition: misc.cpp:222
HRESULT WINAPI DllCanUnloadNow(void)
Definition: misc.cpp:173
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1240
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
STDAPI_(BOOL) DllMain(HINSTANCE hInstance
HRESULT WINAPI RSHELL_CMenuSite_CreateInstance(REFIID riid, LPVOID *ppv)
Definition: CMenuSite.cpp:359
#define lstrlenW
Definition: compat.h:407
#define E_FAIL
Definition: ddrawi.h:102
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: misc.cpp:265
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1094
static HRESULT UnregisterComponent(REFGUID clsid)
Definition: misc.cpp:130
static LSTATUS _RegSetStringValueW(HKEY hKey, LPCWSTR lpValueName, LPCWSTR lpStringData)
Definition: misc.cpp:84
DWORD dwReason
Definition: misc.cpp:154
HINSTANCE hInstance
Definition: charmap.c:20
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
unsigned int BOOL
Definition: ntddk_ex.h:94
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
STDAPI DllUnregisterServer(void)
Definition: misc.cpp:196
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DllMain(IN HINSTANCE hinstDLL, IN DWORD dwReason, IN LPVOID lpvReserved)
Definition: kbsdll.c:83
#define DLL_PROCESS_DETACH
Definition: compat.h:119
virtual HRESULT WINAPI LockServer(BOOL fLock)
Definition: misc.cpp:254
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:541
CRShellModule gModule
Definition: misc.cpp:79
const GUID CLSID_StartMenu
virtual HRESULT WINAPI CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
Definition: misc.cpp:229
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
HRESULT UnregisterComCat()
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2343
unsigned long DWORD
Definition: ntddk_ex.h:95
CAtlWinModule gWinModule
Definition: misc.cpp:80
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
HRESULT WINAPI RSHELL_CStartMenu_CreateInstance(REFIID riid, void **ppv)
Definition: CStartMenu.cpp:418
REFCLSID clsid
Definition: msctf.c:84
static const WCHAR L[]
Definition: oid.c:1250
DWORD WINAPI WinList_Init(void)
Definition: misc.cpp:68
unsigned char BYTE
Definition: mem.h:68
REFIID LPVOID * ppvObject
Definition: precomp.h:44
HRESULT RegisterComCat()
const GUID CLSID_MenuBandSite
static HRESULT RegisterComponent(REFGUID clsid, LPCWSTR szDisplayName)
Definition: misc.cpp:91
#define S_OK
Definition: intsafe.h:59
DWORD LPVOID fImpLoad
Definition: misc.cpp:155
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:561
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
#define E_NOTIMPL
Definition: ddrawi.h:99
const GUID CLSID_QuickLaunchBand
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
STDAPI DllRegisterServer(void)
Definition: misc.cpp:180
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
HRESULT WINAPI RSHELL_CMenuDeskBar_CreateInstance(REFIID riid, LPVOID *ppv)
#define END_COM_MAP()
Definition: atlcom.h:552
HRESULT WINAPI RSHELL_CMergedFolder_CreateInstance(REFIID riid, LPVOID *ppv)
const GUID IID_IClassFactory
#define IsEqualCLSID(rclsid1, rclsid2)
Definition: guiddef.h:91
#define REG_SZ
Definition: layer.c:22