ReactOS 0.4.15-dev-7834-g00c4b3d
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
57extern "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
74class CRShellModule : public CComModule
75{
76public:
77};
78
80CAtlWinModule gWinModule;
81
83
84static 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
172WINAPI
174{
175 gModule.DllCanUnloadNow();
176 return S_FALSE;
177}
178
179STDAPI
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
192 return S_OK;
193}
194
195STDAPI
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{
215private:
217
218public:
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
255 {
256 return E_NOTIMPL;
257 }
258
262};
263
264STDAPI
266REFCLSID rclsid,
268LPVOID *ppv)
269{
270 if (!ppv)
271 return E_INVALIDARG;
272
273 *ppv = NULL;
274
275 return ShellObjectCreatorInit<CRShellClassFactory>(rclsid, riid, ppv);
276}
const GUID CLSID_QuickLaunchBand
HRESULT UnregisterComCat()
HRESULT RegisterComCat()
static HRESULT UnregisterComponent(REFGUID clsid)
Definition: misc.cpp:130
STDAPI DllRegisterServer(void)
Definition: misc.cpp:180
CAtlWinModule gWinModule
Definition: misc.cpp:80
DWORD LPVOID fImpLoad
Definition: misc.cpp:155
STDAPI DllUnregisterServer(void)
Definition: misc.cpp:196
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
static HRESULT RegisterComponent(REFGUID clsid, LPCWSTR szDisplayName)
Definition: misc.cpp:91
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: misc.cpp:265
HRESULT WINAPI RSHELL_CStartMenu_CreateInstance(REFIID riid, void **ppv)
Definition: CStartMenu.cpp:592
static LSTATUS _RegSetStringValueW(HKEY hKey, LPCWSTR lpValueName, LPCWSTR lpStringData)
Definition: misc.cpp:84
HRESULT WINAPI RSHELL_CMenuBand_CreateInstance(REFIID riid, LPVOID *ppv)
Definition: CMenuBand.cpp:1312
HRESULT WINAPI RSHELL_CMenuSite_CreateInstance(REFIID riid, LPVOID *ppv)
Definition: CMenuSite.cpp:360
HRESULT WINAPI RSHELL_CMenuDeskBar_CreateInstance(REFIID riid, LPVOID *ppv)
DWORD WINAPI WinList_Init(void)
Definition: misc.cpp:68
CRShellModule gModule
Definition: misc.cpp:79
HRESULT WINAPI DllCanUnloadNow(void)
Definition: misc.cpp:173
HRESULT WINAPI RSHELL_CMergedFolder_CreateInstance(REFIID riid, LPVOID *ppv)
DWORD dwReason
Definition: misc.cpp:154
#define STDAPI_(t)
Definition: basetyps.h:42
#define STDAPI
Definition: basetyps.h:41
const GUID IID_IClassFactory
#define RegCloseKey(hKey)
Definition: registry.h:49
HINSTANCE hInstance
Definition: charmap.c:19
virtual HRESULT WINAPI CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
Definition: misc.cpp:229
HRESULT Initialize(REFGUID clsid)
Definition: misc.cpp:222
virtual HRESULT WINAPI LockServer(BOOL fLock)
Definition: misc.cpp:254
virtual ~CRShellClassFactory()
Definition: misc.cpp:220
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
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:1096
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
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:4882
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1239
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define MAX_PATH
Definition: compat.h:34
#define lstrlenW
Definition: compat.h:750
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
INT WINAPI StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
Definition: compobj.c:2434
const GUID CLSID_MenuBandSite
const GUID CLSID_StartMenu
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
BOOL WINAPI DllMain(IN HINSTANCE hinstDLL, IN DWORD dwReason, IN LPVOID lpvReserved)
Definition: kbsdll.c:95
#define REG_SZ
Definition: layer.c:22
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define END_COM_MAP()
Definition: atlcom.h:592
REFCLSID clsid
Definition: msctf.c:82
#define KEY_WRITE
Definition: nt_native.h:1031
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define L(x)
Definition: ntvdm.h:50
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
#define IsEqualCLSID(rclsid1, rclsid2)
Definition: guiddef.h:96
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
Definition: scsiwmi.h:51
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
#define E_NOINTERFACE
Definition: winerror.h:2364
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned char BYTE
Definition: xxhash.c:193