forked from microsoft/Windows-driver-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllsup.cpp
More file actions
177 lines (123 loc) · 3.96 KB
/
dllsup.cpp
File metadata and controls
177 lines (123 loc) · 3.96 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*++
Copyright (C) Microsoft Corporation, All Rights Reserved.
Module Name:
dllsup.cpp
Abstract:
This module contains the implementation of the UMDF VirtualSerial Sample
Driver's entry point and its exported functions for providing COM support.
This module can be copied without modification to a new UMDF driver. It
depends on some of the code in comsup.cpp & comsup.h to handle DLL
registration and creating the first class factory.
This module is dependent on the following defines:
MYDRIVER_TRACING_ID - A wide string passed to WPP when initializing
tracing. For example, VirtualSerial uses
L"Microsoft\\UMDF\\VirtualSerial"
MYDRIVER_CLASS_ID - A GUID encoded in struct format used to
initialize the driver's ClassID.
These are defined in internal.h for the sample. If you choose
to use a different primary include file, you should ensure they are
defined there as well.
Environment:
WDF User-Mode Driver Framework (WDF:UMDF)
--*/
#include "internal.h"
#include "dllsup.tmh"
const GUID CLSID_MyDriverCoClass = MYDRIVER_CLASS_ID;
BOOL
WINAPI
DllMain(
HINSTANCE ModuleHandle,
DWORD Reason,
PVOID /* Reserved */
)
/*++
Routine Description:
This is the entry point and exit point for the I/O trace driver. This
does very little as the I/O trace driver has minimal global data.
This method initializes tracing.
Arguments:
ModuleHandle - the DLL handle for this module.
Reason - the reason this entry point was called.
Reserved - unused
Return Value:
TRUE
--*/
{
UNREFERENCED_PARAMETER( ModuleHandle );
if (DLL_PROCESS_ATTACH == Reason)
{
//
// Initialize tracing.
//
WPP_INIT_TRACING(MYDRIVER_TRACING_ID);
}
else if (DLL_PROCESS_DETACH == Reason)
{
//
// Cleanup tracing.
//
WPP_CLEANUP();
}
return TRUE;
}
HRESULT
STDAPICALLTYPE
DllGetClassObject(
_In_ REFCLSID ClassId,
_In_ REFIID InterfaceId,
_Outptr_ LPVOID *Interface
)
/*++
Routine Description:
This routine is called by COM in order to instantiate the
driver callback object and do an initial query interface on it.
This method only creates an instance of the driver's class factory, as this
is the minimum required to support UMDF.
Arguments:
ClassId - the CLSID of the object being "gotten"
InterfaceId - the interface the caller wants from that object.
Interface - a location to store the referenced interface pointer
Return Value:
S_OK if the function succeeds or error indicating the cause of the
failure.
--*/
{
PCClassFactory factory;
HRESULT hr = S_OK;
*Interface = NULL;
//
// If the CLSID doesn't match that of our "coclass" (defined in the IDL
// file) then we can't create the object the caller wants. This may
// indicate that the COM registration is incorrect, and another CLSID
// is referencing this drvier.
//
if (IsEqualCLSID(ClassId, CLSID_MyDriverCoClass) == false)
{
Trace(
TRACE_LEVEL_ERROR,
L"ERROR: Called to create instance of unrecognized class (%!GUID!)",
&ClassId
);
return CLASS_E_CLASSNOTAVAILABLE;
}
//
// Create an instance of the class factory for the caller.
//
factory = new CClassFactory();
if (NULL == factory)
{
hr = E_OUTOFMEMORY;
}
//
// Query the object we created for the interface the caller wants. After
// that we release the object. This will drive the reference count to
// 1 (if the QI succeeded an referenced the object) or 0 (if the QI failed).
// In the later case the object is automatically deleted.
//
if (SUCCEEDED(hr))
{
hr = factory->QueryInterface(InterfaceId, Interface);
factory->Release();
}
return hr;
}