blob: 2c28f16e17c449556ffc5b5c8837f6eefb5f6deb (
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
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
|
/*++
Copyright (C) Microsoft Corporation, All Rights Reserved.
Module Name:
Driver.cpp
Abstract:
This module contains the implementation of the UMDF Socketecho Sample's
core driver callback object.
Environment:
Windows User-Mode Driver Framework (WUDF)
--*/
#include "internal.h"
#include "driver.tmh"
DECLARE_TRACING_TLS;
STDMETHODIMP
CMyDriver::OnInitialize(
_In_ IWDFDriver* /*pWdfDriver*/
)
/*++
Routine Description:
This routine is invoked by the framework at driver load .
This method will invoke the Winsock Library for using
Winsock API in this driver.
Arguments:
pWdfDriver - Framework driver object
Return Value:
S_OK if successful, or error otherwise.
--*/
{
MethodEntry("...");
HRESULT hr = S_OK;
WSADATA wsaData;
int result = WSAStartup(MAKEWORD(2,2), &wsaData);
if (result != 0)
{
hr = HRESULT_FROM_WIN32(WSAGetLastError());
TraceErrorHR(hr, "Failed to initialize Winsock 2.0");
}
MethodReturnHR(hr);
}
STDMETHODIMP_(void)
CMyDriver::OnDeinitialize(
_In_ IWDFDriver* /*pWdfDriver*/
)
/*++
Routine Description:
The FX invokes this method when it unloads the driver.
This routine will Cleanup Winsock library
Arguments:
pWdfDriver - the Fx driver object.
Return Value:
None
--*/
{
MethodEntry("...");
WSACleanup();
MethodReturnVoid();
}
STDMETHODIMP
CMyDriver::OnDeviceAdd(
_In_ IWDFDriver *FxWdfDriver,
_In_ IWDFDeviceInitialize *FxDeviceInit
)
/*++
Routine Description:
The FX invokes this method when it wants to install our driver on a device
stack. This method creates a device callback object, then calls the Fx
to create an Fx device object and associate the new callback object with
it.
Arguments:
FxWdfDriver - the Fx driver object.
FxDeviceInit - the initialization information for the device.
Return Value:
status
--*/
{
MethodEntry("...");
//
// Create a new instance of our device callback object
//
CComObject<CMyDevice> * device;
HRESULT hr = CComObject<CMyDevice>::CreateInstance(&device);
if (SUCCEEDED(hr))
{
device->AddRef();
hr = device->Initialize(FxWdfDriver, FxDeviceInit);
if (SUCCEEDED(hr))
{
//
// If that succeeded then call the device's configure method. This
// allows the device to create any queues or other structures that it
// needs now that the corresponding fx device object has been created.
//
hr = device->Configure();
}
//
// Release the reference we took on the device object.
// The framework took its own references on the object's callback interfaces
// when we called FxWdfDriver->CreateDevice, and will manage the object's lifetime.
//
SAFE_RELEASE(device);
}
MethodReturnHR(hr);
}
|