[ATL] Added CComPtr.CoCreateInstance helper methods (#5905)

This commit is contained in:
Whindmar Saksit 2023-11-13 11:03:05 +01:00 committed by GitHub
parent 8d54c2d433
commit c6ec8d924e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -98,6 +98,19 @@ public:
p->Release();
}
HRESULT CoCreateInstance(REFCLSID rclsid, REFIID riid, LPUNKNOWN pOuter = NULL, DWORD ClsCtx = CLSCTX_ALL)
{
ATLASSERT(!p);
return ::CoCreateInstance(rclsid, pOuter, ClsCtx, riid, (void**)&p);
}
HRESULT CoCreateInstance(LPCOLESTR ProgID, REFIID riid, LPUNKNOWN pOuter = NULL, DWORD ClsCtx = CLSCTX_ALL)
{
CLSID clsid;
HRESULT hr = CLSIDFromProgID(ProgID, &clsid);
return FAILED(hr) ? hr : CoCreateInstance(clsid, riid, pOuter, ClsCtx);
}
T *operator = (T *lp)
{
T* pOld = p;
@ -142,6 +155,16 @@ public:
return *this;
}
HRESULT CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pOuter = NULL, DWORD ClsCtx = CLSCTX_ALL)
{
return CoCreateInstance(rclsid, __uuidof(T), pOuter, ClsCtx);
}
HRESULT CoCreateInstance(LPCOLESTR ProgID, LPUNKNOWN pOuter = NULL, DWORD ClsCtx = CLSCTX_ALL)
{
return CoCreateInstance(ProgID, __uuidof(T), pOuter, ClsCtx);
}
#endif
void Release()