MSIX: use com_object_factory for powerrename

This commit is contained in:
yuyoyuppe
2020-03-04 13:40:32 +03:00
committed by Andrey Nekrasov
parent 39cac396f5
commit 84fbdba9f5

View File

@@ -4,6 +4,7 @@
#include <CLSID.h>
#include <PowerRenameExt.h>
#include <common.h>
#include <com_object_factory.h>
std::atomic<DWORD> g_dwModuleRefCount = 0;
@@ -24,69 +25,6 @@ void ModuleRelease()
}
HINSTANCE g_hInst = 0;
class CPowerRenameClassLocalFactory : public IClassFactory
{
public:
CPowerRenameClassLocalFactory(_In_ REFCLSID clsid) :
_clsid(clsid)
{
}
// IUnknown methods
IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppv)
{
static const QITAB qit[] = {
QITABENT(CPowerRenameClassLocalFactory, IClassFactory),
{ 0 }
};
return QISearch(this, qit, riid, ppv);
}
IFACEMETHODIMP_(ULONG)
AddRef()
{
return ++_refCount;
}
IFACEMETHODIMP_(ULONG)
Release()
{
LONG refCount = --_refCount;
return refCount;
}
// IClassFactory methods
IFACEMETHODIMP CreateInstance(_In_opt_ IUnknown* punkOuter, _In_ REFIID riid, _Outptr_ void** ppv)
{
*ppv = NULL;
HRESULT hr;
if (punkOuter)
{
hr = CLASS_E_NOAGGREGATION;
}
else
{
if (_clsid == CLSID_PowerRenameMenu)
{
hr = CPowerRenameMenu::s_CreateInstance(punkOuter, riid, ppv);
}
else
{
hr = CLASS_E_CLASSNOTAVAILABLE;
}
}
return hr;
}
IFACEMETHODIMP LockServer(BOOL)
{
return S_OK;
}
private:
std::atomic<long> _refCount;
CLSID _clsid;
};
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE,
@@ -96,7 +34,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
main_thread_id = GetCurrentThreadId();
winrt::init_apartment();
g_hInst = hInstance;
CPowerRenameClassLocalFactory factory{CLSID_PowerRenameMenu};
com_object_factory<CPowerRenameMenu> factory;
DWORD token;
if (!SUCCEEDED(CoRegisterClassObject(CLSID_PowerRenameMenu, &factory, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &token)))
{