mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
84 lines
1.4 KiB
C++
84 lines
1.4 KiB
C++
|
|
#include "pch.h"
|
||
|
|
#include "ClassFactory.h"
|
||
|
|
#include "GcodePreviewHandler.h"
|
||
|
|
|
||
|
|
#include <new>
|
||
|
|
#include <Shlwapi.h>
|
||
|
|
|
||
|
|
extern long g_cDllRef;
|
||
|
|
|
||
|
|
ClassFactory::ClassFactory() :
|
||
|
|
m_cRef(1)
|
||
|
|
{
|
||
|
|
InterlockedIncrement(&g_cDllRef);
|
||
|
|
}
|
||
|
|
|
||
|
|
ClassFactory::~ClassFactory()
|
||
|
|
{
|
||
|
|
InterlockedDecrement(&g_cDllRef);
|
||
|
|
}
|
||
|
|
|
||
|
|
//
|
||
|
|
// IUnknown
|
||
|
|
//
|
||
|
|
|
||
|
|
IFACEMETHODIMP ClassFactory::QueryInterface(REFIID riid, void **ppv)
|
||
|
|
{
|
||
|
|
static const QITAB qit[] = {
|
||
|
|
QITABENT(ClassFactory, IClassFactory),
|
||
|
|
{ 0 },
|
||
|
|
};
|
||
|
|
return QISearch(this, qit, riid, ppv);
|
||
|
|
}
|
||
|
|
|
||
|
|
IFACEMETHODIMP_(ULONG) ClassFactory::AddRef()
|
||
|
|
{
|
||
|
|
return InterlockedIncrement(&m_cRef);
|
||
|
|
}
|
||
|
|
|
||
|
|
IFACEMETHODIMP_(ULONG) ClassFactory::Release()
|
||
|
|
{
|
||
|
|
ULONG cRef = InterlockedDecrement(&m_cRef);
|
||
|
|
if (0 == cRef)
|
||
|
|
{
|
||
|
|
delete this;
|
||
|
|
}
|
||
|
|
return cRef;
|
||
|
|
}
|
||
|
|
|
||
|
|
//
|
||
|
|
// IClassFactory
|
||
|
|
//
|
||
|
|
|
||
|
|
IFACEMETHODIMP ClassFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv)
|
||
|
|
{
|
||
|
|
HRESULT hr = CLASS_E_NOAGGREGATION;
|
||
|
|
|
||
|
|
if (pUnkOuter == NULL)
|
||
|
|
{
|
||
|
|
hr = E_OUTOFMEMORY;
|
||
|
|
|
||
|
|
GcodePreviewHandler* pExt = new (std::nothrow) GcodePreviewHandler();
|
||
|
|
if (pExt)
|
||
|
|
{
|
||
|
|
hr = pExt->QueryInterface(riid, ppv);
|
||
|
|
pExt->Release();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return hr;
|
||
|
|
}
|
||
|
|
|
||
|
|
IFACEMETHODIMP ClassFactory::LockServer(BOOL fLock)
|
||
|
|
{
|
||
|
|
if (fLock)
|
||
|
|
{
|
||
|
|
InterlockedIncrement(&g_cDllRef);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
InterlockedDecrement(&g_cDllRef);
|
||
|
|
}
|
||
|
|
|
||
|
|
return S_OK;
|
||
|
|
}
|