-
Notifications
You must be signed in to change notification settings - Fork 31
/
VariantAdapt.h
51 lines (45 loc) · 976 Bytes
/
VariantAdapt.h
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
49
50
51
#pragma once
template <typename T>
struct _CopyVariantFromAdaptItf
{
static HRESULT copy(VARIANT* p1, const CAdapt< CComPtr<T> >* p2)
{
HRESULT hr = p2->m_T->QueryInterface(
IID_IDispatch,
(void**)&p1->pdispVal
);
if (SUCCEEDED(hr))
{
p1->vt = VT_DISPATCH;
}
else
{
hr = p2->m_T->QueryInterface(
IID_IUnknown,
(void**)&p1->punkVal
);
if( SUCCEEDED(hr) )
{
p1->vt = VT_UNKNOWN;
}
}
return hr;
}
static void init(VARIANT* p) { VariantInit(p); }
static void destroy(VARIANT* p) { VariantClear(p); }
};
template <typename T>
struct _CopyItfFromAdaptItf
{
static HRESULT copy(T** p1, const CAdapt< CComPtr<T> >* p2)
{
*p1 = p2->m_T;
if(*p1)
{
return (*p1)->AddRef(), S_OK;
}
return E_POINTER;
}
static void init(T** p) {}
static void destroy(T** p) { if( *p ) (*p)->Release(); }
};