2020-04-29 13:02:18 -07:00
|
|
|
#include "pch.h"
|
2019-12-19 12:15:54 +03:00
|
|
|
|
|
|
|
#include "resource.h"
|
|
|
|
#include <CLSID.h>
|
|
|
|
#include <PowerRenameExt.h>
|
|
|
|
#include <common.h>
|
2020-03-04 13:40:32 +03:00
|
|
|
#include <com_object_factory.h>
|
2019-12-19 12:15:54 +03:00
|
|
|
|
|
|
|
std::atomic<DWORD> g_dwModuleRefCount = 0;
|
|
|
|
|
|
|
|
DWORD main_thread_id;
|
|
|
|
|
|
|
|
void ModuleAddRef()
|
|
|
|
{
|
|
|
|
++g_dwModuleRefCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModuleRelease()
|
|
|
|
{
|
2019-12-20 16:59:20 +03:00
|
|
|
if (--g_dwModuleRefCount == 0)
|
2019-12-19 12:15:54 +03:00
|
|
|
{
|
2020-02-07 14:21:10 +03:00
|
|
|
// Do nothing and keep the COM server in memory forever. We might want to introduce delayed shutdown and/or
|
|
|
|
// periodic polling whether a user has disabled us in settings. Tracking this in #1217
|
2019-12-19 12:15:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
HINSTANCE g_hInst = 0;
|
|
|
|
|
|
|
|
|
|
|
|
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
2019-12-20 16:59:20 +03:00
|
|
|
_In_opt_ HINSTANCE,
|
|
|
|
_In_ LPWSTR lpCmdLine,
|
|
|
|
_In_ int nCmdShow)
|
2019-12-19 12:15:54 +03:00
|
|
|
{
|
|
|
|
main_thread_id = GetCurrentThreadId();
|
|
|
|
winrt::init_apartment();
|
|
|
|
g_hInst = hInstance;
|
2020-03-04 13:40:32 +03:00
|
|
|
com_object_factory<CPowerRenameMenu> factory;
|
2019-12-19 12:15:54 +03:00
|
|
|
DWORD token;
|
2020-02-07 14:21:10 +03:00
|
|
|
if (!SUCCEEDED(CoRegisterClassObject(CLSID_PowerRenameMenu, &factory, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &token)))
|
2019-12-19 12:15:54 +03:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2019-12-20 16:59:20 +03:00
|
|
|
|
2019-12-19 12:15:54 +03:00
|
|
|
// Run msg loop for the local COM server
|
|
|
|
run_message_loop();
|
|
|
|
|
|
|
|
CoRevokeClassObject(token);
|
|
|
|
winrt::uninit_apartment();
|
|
|
|
return 0;
|
|
|
|
}
|