-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComPtr.cpp
More file actions
49 lines (38 loc) · 1.18 KB
/
ComPtr.cpp
File metadata and controls
49 lines (38 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <RsUtil.h>
#include "ComPtr.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
ECom::ECom(AnsiString FunctionName, HRESULT hr): Exception(""), hr(hr)
{
Message = rsutil::PrintF("%s: error %u == 0x%08x == \"%ls\"",
FunctionName.c_str(),
hr,
hr,
rsutil::GetErrorText(hr).c_str());
}
IUnknown* CoCreateInstance(REFCLSID ClassId, REFIID InterfaceId)
{
IUnknown *pResult;
HRESULT hr = CoCreateInstance(ClassId, NULL, CLSCTX_INPROC_SERVER, InterfaceId, (void**)&pResult);
if (!SUCCEEDED(hr))
throw ECom("CoCreateInstance()", hr);
return pResult;
}
IUnknown* QueryInterface(IUnknown *pIUnknown, REFIID InterfaceId)
{
IUnknown *pResult;
HRESULT hr = pIUnknown->QueryInterface(InterfaceId, (void**)&pResult);
if (!SUCCEEDED(hr))
throw ECom("QueryInterface()", hr);
return pResult;
}
IUnknown* QueryInterface(TComPtr<IUnknown> Unknown, REFIID InterfaceId)
{
return QueryInterface(Unknown.get(), InterfaceId);
}
#ifdef TRACK_REFCOUNTS
std::map<IUnknown*, unsigned> RefCounts;
#endif