Sample Code

Windows Driver Samples/ Toaster Sample Driver/ C++/ umdf/ Toastmon/ Driver.cpp/

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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*++
  
Copyright (C) Microsoft Corporation, All Rights Reserved.
 
Module Name:
 
    Driver.cpp
 
Abstract:
 
    This module contains the implementation of the UMDF Sample's
    core driver callback object.
 
Environment:
 
   Windows User-Mode Driver Framework (WUDF)
 
--*/
 
#include "internal.h"
#include "driver.tmh"
 
HRESULT
CMyDriver::CreateInstance(
    _Out_ PCMyDriver * MyDriver
    )
/*++
  
  Routine Description:
 
    This static method is invoked in order to create and initialize a new
    instance of the driver class.  The caller should arrange for the object
    to be released when it is no longer in use.
 
  Arguments:
 
    MyDriver - a location to store a referenced pointer to the new instance
 
  Return Value:
 
    S_OK if successful, or error otherwise.
 
--*/
{
    PCMyDriver myDriver;
    HRESULT hr;
 
    //
    // Allocate the callback object.
    //
 
    myDriver = new CMyDriver();
 
    if (NULL == myDriver)
    {
        return E_OUTOFMEMORY;
    }
         
    //
    // Initialize the callback object.
    //
 
    hr = myDriver->Initialize();
 
    if (SUCCEEDED(hr))
    {
        //
        // Store a pointer to the new, initialized object in the output
        // parameter.
        //
 
        *MyDriver = myDriver;
    }
    else
    {
 
        //
        // Release the reference on the driver object to get it to delete
        // itself.
        //
 
        myDriver->Release();
    }
 
    return hr;
}
 
HRESULT
CMyDriver::Initialize(
    VOID
    )
/*++
  
  Routine Description:
 
    This method is called to initialize a newly created driver callback object
    before it is returned to the creator.  Unlike the constructor, the
    Initialize method contains operations which could potentially fail.
 
  Arguments:
 
    None
 
  Return Value:
 
    None
 
--*/
{
    return S_OK;
}
 
HRESULT
CMyDriver::QueryInterface(
    _In_ REFIID InterfaceId,
    _Out_ PVOID *Interface
    )
/*++
  
  Routine Description:
 
    This method returns a pointer to the requested interface on the callback
    object.
 
  Arguments:
 
    InterfaceId - the IID of the interface to query/reference
 
    Interface - a location to store the interface pointer.
 
  Return Value:
 
    S_OK if the interface is supported.
    E_NOINTERFACE if it is not supported.
 
--*/
{
    if (IsEqualIID(InterfaceId, __uuidof(IDriverEntry)))
    {
        *Interface = QueryIDriverEntry();
        return S_OK;
    }
    else
    {
        return CUnknown::QueryInterface(InterfaceId, Interface);
    }
}
 
HRESULT
CMyDriver::OnDeviceAdd(
    _In_ IWDFDriver           *FxDriver,
    _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
 
--*/
{
    PCMyDevice myDevice = NULL;
 
    HRESULT hr;
 
    //
    // Create a new instance of our device callback object
    //
 
    hr = CMyDevice::CreateInstance(FxDriver, FxDeviceInit, &myDevice);
 
    //
    // If that succeeded then call the device's construct 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.
    //
 
    if (SUCCEEDED(hr))
    {
        hr = myDevice->Configure();
    }
 
    //
    // Release the reference on the device callback object now that it's been
    // associated with an fx device object.
    //
 
    if (NULL != myDevice)
    {
        myDevice->Release();
    }
 
    return hr;
}

Our Services

  • What our customers say about us?

© 2011-2025 All Rights Reserved. Joya Systems. 4425 South Mopac Building II Suite 101 Austin, TX 78735 Tel: 800-DEV-KERNEL

Privacy Policy. Terms of use. Valid XHTML & CSS