24#include <registry.hxx>
40 const wchar_t*
const GUID_PLACEHOLDER = L
"{GUID}";
41 const wchar_t*
const EXTENSION_PLACEHOLDER = L
"{EXT}";
42 const wchar_t*
const FORWARDKEY_PLACEHOLDER = L
"{FWDKEY}";
44 const wchar_t*
const CLSID_ENTRY = L
"CLSID\\{GUID}\\InProcServer32";
45 const wchar_t*
const SHELLEX_IID_ENTRY = L
"{EXT}\\shellex\\{GUID}";
46 const wchar_t*
const SHELLEX_ENTRY = L
"{EXT}\\shellex";
47 const wchar_t*
const FORWARD_PROPSHEET_MYPROPSHEET_ENTRY = L
"{FWDKEY}\\shellex\\PropertySheetHandlers\\MyPropSheet1";
48 const wchar_t*
const FORWARD_PROPSHEET_ENTRY = L
"{FWDKEY}\\shellex\\PropertySheetHandlers";
49 const wchar_t*
const FORWARD_SHELLEX_ENTRY = L
"{FWDKEY}\\shellex";
51 const wchar_t*
const SHELL_EXTENSION_APPROVED_KEY_NAME = L
"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";
62 while (std::wstring::npos !=
idx)
74 HRESULT RegisterComComponent(
const wchar_t* FilePath,
const CLSID& Guid)
76 std::wstring ClsidEntry = CLSID_ENTRY;
77 SubstitutePlaceholder(ClsidEntry, GUID_PLACEHOLDER,
ClsidToString(Guid));
79 if (!
SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry.c_str(), L
"", FilePath))
82 if (!
SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry.c_str(), L
"ThreadingModel", L
"Apartment"))
88 HRESULT UnregisterComComponent(
const CLSID& Guid)
90 std::wstring tmp = L
"CLSID\\";
95 HRESULT RegisterColumnHandler(
const wchar_t* ModuleFileName)
100 std::wstring tmp = L
"Folder\\shellex\\ColumnHandlers\\";
110 HRESULT UnregisterColumnHandler()
112 std::wstring tmp = L
"Folder\\shellex\\ColumnHandlers\\";
121 HRESULT RegisterInfotipHandler(
const wchar_t* ModuleFileName)
131 tmp = SHELLEX_IID_ENTRY;
133 SubstitutePlaceholder(tmp, GUID_PLACEHOLDER, iid);
141 HRESULT UnregisterInfotipHandler()
148 tmp = SHELLEX_IID_ENTRY;
151 SubstitutePlaceholder(tmp, GUID_PLACEHOLDER, iid);
160 bool HasSubKeys =
true;
167 HRESULT RegisterPropSheetHandler(
const wchar_t* ModuleFileName)
169 std::wstring FwdKeyEntry;
176 FwdKeyEntry = FORWARD_PROPSHEET_MYPROPSHEET_ENTRY;
177 SubstitutePlaceholder(FwdKeyEntry, FORWARDKEY_PLACEHOLDER,
OOFileExtensionTable[
i].RegistryForwardKey);
185 HRESULT UnregisterPropSheetHandler()
187 std::wstring FwdKeyEntry;
191 FwdKeyEntry = FORWARD_PROPSHEET_MYPROPSHEET_ENTRY;
192 SubstitutePlaceholder(FwdKeyEntry, FORWARDKEY_PLACEHOLDER,
OOFileExtensionTable[
i].RegistryForwardKey);
196 FwdKeyEntry = FORWARD_PROPSHEET_ENTRY;
197 SubstitutePlaceholder(FwdKeyEntry, FORWARDKEY_PLACEHOLDER,
OOFileExtensionTable[
i].RegistryForwardKey);
199 bool HasSubKeys =
true;
203 FwdKeyEntry = FORWARD_SHELLEX_ENTRY;
204 SubstitutePlaceholder(FwdKeyEntry, FORWARDKEY_PLACEHOLDER,
OOFileExtensionTable[
i].RegistryForwardKey);
214 HRESULT RegisterThumbviewerHandler(
const wchar_t* ModuleFileName)
224 tmp = SHELLEX_IID_ENTRY;
227 SubstitutePlaceholder(tmp, GUID_PLACEHOLDER, iid);
235 HRESULT UnregisterThumbviewerHandler()
242 tmp = SHELLEX_IID_ENTRY;
245 SubstitutePlaceholder(tmp, GUID_PLACEHOLDER, iid);
254 bool HasSubKeys =
true;
263 HRESULT ApproveShellExtension(
const CLSID& clsid,
const std::wstring& Description)
267 SHELL_EXTENSION_APPROVED_KEY_NAME,
269 Description.c_str());
271 return bRet ? S_OK : E_FAIL;
274 HRESULT UnapproveShellExtension(
const CLSID& Clsid)
278 LONG rc = RegOpenKeyW(
280 SHELL_EXTENSION_APPROVED_KEY_NAME,
283 if (ERROR_SUCCESS == rc)
285 rc = RegDeleteValueW(
289 rc |= RegCloseKey(hkey);
292 return rc == ERROR_SUCCESS ? S_OK : E_FAIL;
308 sizeof(ModuleFileName)/
sizeof(ModuleFileName[0]));
312 if (SUCCEEDED(RegisterColumnHandler(ModuleFileName)))
317 if (SUCCEEDED(RegisterInfotipHandler(ModuleFileName)))
322 if (SUCCEEDED(RegisterPropSheetHandler(ModuleFileName)))
327 if (SUCCEEDED(RegisterThumbviewerHandler(ModuleFileName)))
333 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST,
nullptr,
nullptr);
342 if (FAILED(UnregisterColumnHandler()))
347 if (FAILED(UnregisterInfotipHandler()))
352 if (FAILED(UnregisterPropSheetHandler()))
357 if (FAILED(UnregisterThumbviewerHandler()))
363 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST,
nullptr,
nullptr);
376 return CLASS_E_CLASSNOTAVAILABLE;
378 if ((riid != IID_IUnknown) && (riid != IID_IClassFactory))
379 return E_NOINTERFACE;
#define COLUMN_HANDLER_DESCRIPTIVE_NAME
#define INFOTIP_HANDLER_DESCRIPTIVE_NAME
#define PROPSHEET_HANDLER_DESCRIPTIVE_NAME
#define THUMBVIEWER_HANDLER_DESCRIPTIVE_NAME
const FileExtensionEntry OOFileExtensionTable[]
const size_t OOFileExtensionTableSize
const wchar_t *typedef BOOL
Filepath_t ClsidToString(const CLSID &clsid)
Converts a GUID to its string representation.
bool HasSubkeysRegistryKey(HKEY RootKey, const Filepath_char_t *KeyName, bool &bResult)
May be used to determine if the specified registry key has subkeys The function returns true on succe...
bool DeleteRegistryKey(HKEY RootKey, const Filepath_char_t *KeyName)
Deletes the specified registry key and all of its subkeys Returns true on success.
bool SetRegistryKey(HKEY RootKey, const Filepath_char_t *KeyName, const Filepath_char_t *ValueName, const Filepath_char_t *Value)
Sets a value of the specified registry key, an empty ValueName sets the default value Returns true on...
STDAPI DllRegisterServer()
STDAPI DllUnregisterServer()
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG, LPVOID)
const CLSID CLSID_PROPERTYSHEET_HANDLER
const CLSID CLSID_THUMBVIEWER_HANDLER
const CLSID CLSID_INFOTIP_HANDLER
const CLSID CLSID_COLUMN_HANDLER
HMODULE GetCurrentModuleHandle()
void OutputDebugStringFormatW(LPCWSTR pFormat,...)