ce9c7d2c5caff26a451ab311e6bb4009fafd69e1
[reactos.git] / reactos / drivers / wdm / audio / backpln / stdunk / stdunk.cpp
1 /*
2 TODO:
3 Need to call ASSERT on m_ref_count to ensure it is valid.
4 */
5
6 #define PUT_GUIDS_HERE
7
8 //#include <portcls.h>
9 #include <punknown.h>
10 #include <stdunk.h>
11
12 #include <ntddk.h>
13
14
15 /*
16 HACK ALERT
17 This is a little bit of a hack, but ReactOS doesn't seem to have this
18 defined. TODO: Make the aligned test truly aligned.
19 */
20 #if 0
21 #define IsEqualGUID(a, b) \
22 RtlEqualMemory(&a, &b, sizeof(GUID))
23
24 #define IsEqualGUIDAligned(a, b) \
25 IsEqualGUID(a, b)
26 #endif
27
28 /*
29 Shut the linker up - can also pass -defsym ___cxa_pure_virtual=0
30 */
31 extern "C" void __cxa_pure_virtual(void) {}
32
33 /*
34 IUnknown
35 */
36
37 CUnknown::CUnknown(PUNKNOWN outer_unknown)
38 {
39 m_ref_count = 0;
40
41 if ( outer_unknown )
42 {
43 m_outer_unknown = outer_unknown;
44 }
45 else
46 {
47 m_outer_unknown = PUNKNOWN(static_cast<PNONDELEGATINGUNKNOWN>(this));
48 }
49 }
50
51 CUnknown::~CUnknown()
52 {
53 }
54
55 /*
56 INonDelegatingUnknown
57 */
58
59 STDMETHODIMP_(ULONG)
60 CUnknown::NonDelegatingAddRef(void)
61 {
62 InterlockedIncrement(&m_ref_count);
63 return m_ref_count;
64 }
65
66 STDMETHODIMP_(ULONG)
67 CUnknown::NonDelegatingRelease(void)
68 {
69 if ( InterlockedDecrement(&m_ref_count) == 0 )
70 {
71 delete this;
72 return 0;
73 }
74
75 return m_ref_count;
76 }
77
78 STDMETHODIMP_(NTSTATUS)
79 CUnknown::NonDelegatingQueryInterface(
80 IN REFIID iid,
81 IN PVOID* ppvoid)
82 {
83 //if ( RtlEqualMemory(&iid, &IID_IUnknown, sizeof(GUID)) )
84 {
85 *ppvoid = (PVOID)((PUNKNOWN) this);
86 }
87 // else
88 {
89 *ppvoid = NULL;
90 }
91
92 if ( *ppvoid )
93 {
94 ((PUNKNOWN)(*ppvoid))->AddRef();
95 return STATUS_SUCCESS;
96 }
97
98 return STATUS_INVALID_PARAMETER;
99 }