-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCDynamicWrapperEx.cpp
More file actions
97 lines (86 loc) · 3.07 KB
/
Copy pathCDynamicWrapperEx.cpp
File metadata and controls
97 lines (86 loc) · 3.07 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @file CDynamicWrapperEx.cpp
* @date 01-10-2020
* @author Paul Laine (@am0nsec)
* @version 1.0
* @brief DynamicWrapperEx class factory definition.
* @details
* @link https://github.com/am0nsec/DynamicWrapperEx
* @copyright This project has been released under the GNU Public License v3 license.
*/
#include <windows.h>
#include <memory>
#include "IDynamicWrapperEx.hpp"
#include "CDynamicWrapperEx.hpp"
/**
* @brief Constructor.
*/
CDynamicWrapperEx::CDynamicWrapperEx() { }
/**
* @brief Destructor.
*/
CDynamicWrapperEx::~CDynamicWrapperEx() { }
/**
* @brief Queries a COM object for a pointer to one of its interface.
* @param riid A reference to the interface identifier (IID) of the interface being queried for.
* @param ppvObject The address of a pointer to an interface with the IID specified in the riid parameter.
* @return Whether an interface has been found.
*/
HRESULT STDMETHODCALLTYPE CDynamicWrapperEx::QueryInterface(
_In_ REFIID riid,
_Out_ LPVOID* ppvObject
) {
if (riid == IID_IUnknown || riid == IID_IClassFactory || riid == CLSID_CDynamicWrapperEx) {
*ppvObject = this;
this->AddRef();
return S_OK;
}
*ppvObject = NULL;
return E_NOINTERFACE;
}
/**
* @brief Increment the number of references.
* @return Number of remaining references.
*/
ULONG STDMETHODCALLTYPE CDynamicWrapperEx::AddRef(VOID) {
return InterlockedIncrement(&this->m_dwReference);
}
/**
* @brief Decrement the number of references.
* @return Number of remaining references.
*/
ULONG STDMETHODCALLTYPE CDynamicWrapperEx::Release(VOID) {
return InterlockedDecrement(&this->m_dwReference);
}
/**
* @brief Creates an uninitialized object.
* @param pUnkOuter Address to an IUknown interface if part of an aggregation.
* @param riid A reference to the identifier of the interface to be used to communicate with the newly created object.
* @param ppvObject The address of pointer variable that receives the interface pointer requested in riid.
* @return Whether the object has been successfully created.
*/
HRESULT STDMETHODCALLTYPE CDynamicWrapperEx::CreateInstance(
_In_ IUnknown* pUnkOuter,
_In_ REFIID riid,
_Out_ LPVOID* ppvObject
) {
if (pUnkOuter != NULL)
return CLASS_E_NOAGGREGATION;
IDynamicWrapperEx* pIDynamicWrapperEx = new IDynamicWrapperEx();
if (pIDynamicWrapperEx == nullptr)
return E_OUTOFMEMORY;
HRESULT hr = pIDynamicWrapperEx->QueryInterface(riid, ppvObject);
this->m_pIDynamicWrapperEx = reinterpret_cast<IDynamicWrapperEx*>(ppvObject);
pIDynamicWrapperEx->Release();
return hr;
}
/**
* @brief Locks an object application open in memory. This enables instances to be created more quickly.
* @param fLock If TRUE, increments the lock count; if FALSE, decrements the lock count.
* @return Whether the function executed successfully.
*/
HRESULT STDMETHODCALLTYPE CDynamicWrapperEx::LockServer(
_In_ BOOL fLock
) {
return ::CoLockObjectExternal(this, fLock, TRUE);
}