PowerToys/tools/HandlesExperiment/ContextMenuEntry/dllmain.cpp

76 lines
1.6 KiB
C++
Raw Normal View History

2022-09-09 17:23:38 +08:00
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
// Additional libraries to link
#pragma comment(lib, "shlwapi")
2022-09-12 18:41:59 +08:00
#include "Registry.h"
#include "ClassFactory.h"
2022-09-12 18:41:59 +08:00
namespace globals
{
HMODULE instance;
std::atomic<ULONG> ref_count;
}
2022-09-12 18:41:59 +08:00
2022-09-09 17:23:38 +08:00
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
globals::instance = hModule;
2022-09-12 18:41:59 +08:00
break;
2022-09-09 17:23:38 +08:00
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
2022-09-12 18:41:59 +08:00
STDAPI DllRegisterServer()
{
if (!add_registry_keys())
{
// Best effort here
delete_registry_keys();
return E_FAIL;
}
return S_OK;
}
STDAPI DllUnregisterServer()
{
return delete_registry_keys() ? S_OK : E_FAIL;
}
STDAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void** ppv)
{
HRESULT result = E_FAIL;
*ppv = NULL;
ClassFactory* class_factory = new (std::nothrow) ClassFactory(clsid);
if (class_factory)
{
result = class_factory->QueryInterface(riid, ppv);
class_factory->Release();
}
return result;
}
STDAPI DllCanUnloadNow(void)
{
return globals::ref_count == 0 ? S_OK : S_FALSE;
}
2022-09-09 17:23:38 +08:00
// Things to implement:
2022-09-09 20:44:40 +08:00
// 1. (DONE) A class which implements IExplorerCommand
// 2. (DONE) A class which implements IClassFactory
2022-09-12 18:41:59 +08:00
// 3. (DONE) DLL register/unregister functions which will create registry entries
// 4. (DONE) Other DLL exported functions