Skip to content

Commit

Permalink
Disabled old dll registering/unregistering code in favor of microsoft…
Browse files Browse the repository at this point in the history
… provided code as described in solution 2 of #113.
  • Loading branch information
end2endzone committed Feb 7, 2023
1 parent 06b6b9c commit ffcc940
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
54 changes: 52 additions & 2 deletions src/shellextension/shellext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
//#include "PropertyManager.h"
#include "SaUtils.h"

#include "reg.h"

#include <assert.h>

//Declarations
Expand Down Expand Up @@ -1111,7 +1113,7 @@ STDAPI DllCanUnloadNow(void)
return S_FALSE;
}

STDAPI DllRegisterServer(void)
STDAPI DllRegisterServer_DISABLED(void)
{
const std::string guid_str_tmp = GuidToString(SHELLANYTHING_SHELLEXTENSION_CLSID).c_str();
const char* guid_str = guid_str_tmp.c_str();
Expand Down Expand Up @@ -1234,7 +1236,7 @@ STDAPI DllRegisterServer(void)
return S_OK;
}

STDAPI DllUnregisterServer(void)
STDAPI DllUnregisterServer_DISABLED(void)
{
const std::string guid_str_tmp = GuidToString(SHELLANYTHING_SHELLEXTENSION_CLSID).c_str();
const char* guid_str = guid_str_tmp.c_str();
Expand Down Expand Up @@ -1313,6 +1315,54 @@ STDAPI DllUnregisterServer(void)
return S_OK;
}

STDAPI DllRegisterServer(void)
{
HRESULT hr;

wchar_t szModule[MAX_PATH];
if (GetModuleFileNameW(g_hmodDll, szModule, ARRAYSIZE(szModule)) == 0)
{
hr = HRESULT_FROM_WIN32(GetLastError());
return hr;
}

// Register the component.
hr = RegisterInprocServer(szModule, SHELLANYTHING_SHELLEXTENSION_CLSID,
ShellExtensionClassNameW,
L"Apartment");
if (SUCCEEDED(hr))
{
// Register the context menu handler. The context menu handler is
// associated with the any file class.
// Control the visibility in QueryContextMenu
hr = RegisterShellExtContextMenuHandler(L"*", SHELLANYTHING_SHELLEXTENSION_CLSID, ShellExtensionClassNameW);
}

return hr;
}

STDAPI DllUnregisterServer(void)
{
HRESULT hr = S_OK;

wchar_t szModule[MAX_PATH];
if (GetModuleFileNameW(g_hmodDll, szModule, ARRAYSIZE(szModule)) == 0)
{
hr = HRESULT_FROM_WIN32(GetLastError());
return hr;
}

// Unregister the component.
hr = UnregisterInprocServer(SHELLANYTHING_SHELLEXTENSION_CLSID);
if (SUCCEEDED(hr))
{
// Unregister the context menu handler.
hr = UnregisterShellExtContextMenuHandler(L"*", SHELLANYTHING_SHELLEXTENSION_CLSID);
}

return hr;
}

void InstallDefaultConfigurations(const std::string& config_dir)
{
std::string app_path = GetCurrentModulePathUtf8();
Expand Down
2 changes: 2 additions & 0 deletions src/shellextension/shellext.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
//Shell extension GUID
static const GUID SHELLANYTHING_SHELLEXTENSION_CLSID = { 0xb0d35103, 0x86a1, 0x471c, { 0xa6, 0x53, 0xe1, 0x30, 0xe3, 0x43, 0x9a, 0x3b } }; //this is the CLSID (GUID) or our Shell Extension, {B0D35103-86A1-471C-A653-E130E3439A3B}
static const char* ShellExtensionClassName = "ShellExtension.ShellAnything"; //no space in string
static const wchar_t* ShellExtensionClassNameW = L"ShellExtension.ShellAnything"; //no space in string
static const char* ShellExtensionDescription = "ShellAnything Class";
static const wchar_t* ShellExtensionDescriptionW = L"ShellAnything Class";

class CCriticalSection
{
Expand Down

0 comments on commit ffcc940

Please sign in to comment.