summaryrefslogtreecommitdiff
path: root/network/wlan/ihvsampleui/iunk.h
blob: 9b8242c56afc73785452703951c81d52b1512048 (plain)
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
52
53
54
//
// Copyright (C) Microsoft Corporation 2005
// IHV UI Extension sample
//

// Common macro based implementation of IUnknown
// using a interface table approach

#define IMPLEMENT_REFCOUNT()\
    ULONG m_crefCount;\
    \
    STDMETHODIMP_(ULONG) AddRef(void)\
    {\
        return InterlockedIncrement((PLONG)&m_crefCount);\
    }\
    \
    _At_(this, __drv_aliasesMem)\
    STDMETHODIMP_(ULONG) Release(void)\
    {\
        ULONG res = InterlockedDecrement((PLONG)&m_crefCount);\
        if (res == 0)\
        {\
           delete this;\
        }\
        return res;\
    }

#define BEGIN_INTERFACE_TABLE()\
    IMPLEMENT_REFCOUNT()\
    STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject)\
    {\
        if (riid == IID_IUnknown)\
        {\
            *ppvObject = reinterpret_cast<IUnknown*>(this);\
        }

#define IMPLEMENTS_INTERFACE(Itf)\
        else if (riid == IID_ ## Itf)\
        {\
            *ppvObject = static_cast<Itf*>(this);\
        }

#define END_INTERFACE_TABLE()\
        else \
        {\
           *ppvObject = NULL;\
            return E_NOINTERFACE;\
        }\
        \
        reinterpret_cast<IUnknown *>(*ppvObject)->AddRef();\
        \
        return S_OK;\
    }