void CQueue::OnDeviceIoControl( __in IWDFIoQueue* pQueue, __in IWDFIoRequest* pRequest, __in ULONG ControlCode, __in SIZE_T /*InputBufferSizeInBytes*/, __in SIZE_T /*OutputBufferSizeInBytes*/ ) /*++ Routine Description: The framework calls this function when somone has called DeviceIoControl on the device. Arguments: Return Value: None --*/ { HRESULT hr = S_OK; IWDFDevice *pDevice = NULL; Trace(TRACE_LEVEL_INFORMATION,"%!FUNC!"); // // Retrieve the queue's parent device object // pQueue->GetDevice(&pDevice); WUDF_TEST_DRIVER_ASSERT(pDevice); switch (ControlCode) { case IOCTL_TOASTER_DONT_DISPLAY_IN_UI_DEVICE: // // This is just an example on how to hide your device in the // device manager. Please remove your code when you adapt this // sample for your hardware. // pDevice->SetPnpState(WdfPnpStateDontDisplayInUI, WdfTrue); pDevice->CommitPnpState(); break; default: hr = E_FAIL; //invalid request Trace(TRACE_LEVEL_ERROR,"%!FUNC! Invalid IOCTL %!hresult!",hr); } pRequest->Complete(hr); return; }
HRESULT CVDevDevice::Initialize ( _In_ IWDFDriver * FxDriver, _In_ IWDFDeviceInitialize * FxDeviceInit) /*++ Routine Description: This method initializes the device callback object and creates the partner device object. Arguments: FxDeviceInit - the settings for this device. Return Value: HRESTULT indication of success or failure --*/ { IWDFDevice * fxDevice = NULL; HRESULT hr = S_OK; Enter(); FxDeviceInit->SetLockingConstraint (None); FxDeviceInit->SetFilter(); { IUnknown * unknown = this->QueryIUnknown (); hr = FxDriver->CreateDevice (FxDeviceInit, unknown, &fxDevice); unknown->Release (); } if (SUCCEEDED (hr)) { m_FxDevice = fxDevice; // // We can release the reference as the lifespan is tied to the // framework object. // fxDevice->Release(); } ExitHR(hr); return hr; }
HRESULT CMyDevice::Initialize( _In_ IWDFDriver * FxDriver, _In_ IWDFDeviceInitialize * FxDeviceInit ) /*++ Routine Description: This method initializes the device callback object and creates the partner device object. The method should perform any device-specific configuration that: * could fail (these can't be done in the constructor) * must be done before the partner object is created -or- * can be done after the partner object is created and which aren't influenced by any device-level parameters the parent (the driver in this case) might set. Arguments: FxDeviceInit - the settings for this device. Return Value: status. --*/ { IWDFDevice *fxDevice = NULL; HRESULT hr = S_OK; // // TODO: If you're writing a filter driver then indicate that here. // // FxDeviceInit->SetFilter(); // // // Set no locking unless you need an automatic callbacks synchronization // FxDeviceInit->SetLockingConstraint(None); // // TODO: Any per-device initialization which must be done before // creating the partner object. // // // Create a new FX device object and assign the new callback object to // handle any device level events that occur. // // // QueryIUnknown references the IUnknown interface that it returns // (which is the same as referencing the device). We pass that to // CreateDevice, which takes its own reference if everything works. // if (SUCCEEDED(hr)) { IUnknown *unknown = this->QueryIUnknown(); hr = FxDriver->CreateDevice(FxDeviceInit, unknown, &fxDevice); unknown->Release(); } // // If that succeeded then set our FxDevice member variable. // if (SUCCEEDED(hr)) { m_FxDevice = fxDevice; // // Drop the reference we got from CreateDevice. Since this object // is partnered with the framework object they have the same // lifespan - there is no need for an additional reference. // fxDevice->Release(); } return hr; }
HRESULT CMyDevice::Initialize( __in IWDFDriver * FxDriver, __in IWDFDeviceInitialize * FxDeviceInit ) /*++ Routine Description: This method initializes the device callback object and creates the partner device object. The method should perform any device-specific configuration that: * could fail (these can't be done in the constructor) * must be done before the partner object is created -or- * can be done after the partner object is created and which aren't influenced by any device-level parameters the parent (the driver in this case) might set. Arguments: FxDeviceInit - the settings for this device. Return Value: status. --*/ { IWDFDevice *fxDevice = NULL; HRESULT hr = S_OK; // // TODO: If you're writing a filter driver then indicate that here. // // FxDeviceInit->SetFilter(); // // // Set no locking unless you need an automatic callbacks synchronization // FxDeviceInit->SetLockingConstraint(None); // // Only one driver in the stack can be the Power policy owner (PPO). // // NOTE: If we want UMDF to be the PPO we also ask WinUsb.sys // to not set itself as the PPO by setting the // WinUsbPowerPolicyOwnershipDisabled key through // an AddReg in the INF. // #if defined(_NOT_POWER_POLICY_OWNER_) FxDeviceInit->SetPowerPolicyOwnership(FALSE); #else FxDeviceInit->SetPowerPolicyOwnership(TRUE); #endif // // TODO: Any per-device initialization which must be done before // creating the partner object. // // // Create a new FX device object and assign the new callback object to // handle any device level events that occur. // // // QueryIUnknown references the IUnknown interface that it returns // (which is the same as referencing the device). We pass that to // CreateDevice, which takes its own reference if everything works. // if (SUCCEEDED(hr)) { IUnknown *unknown = this->QueryIUnknown(); hr = FxDriver->CreateDevice(FxDeviceInit, unknown, &fxDevice); unknown->Release(); } // // If that succeeded then set our FxDevice member variable. // if (SUCCEEDED(hr)) { // // Drop the reference we got from CreateDevice. Since this object // is partnered with the framework object they have the same // lifespan - there is no need for an additional reference. // fxDevice->Release(); IWDFDevice2 *fxDevice2 = NULL; HRESULT hrQI = fxDevice->QueryInterface(__uuidof(IWDFDevice2), (void**) &fxDevice2); WUDF_TEST_DRIVER_ASSERT(SUCCEEDED(hrQI) && fxDevice2); m_FxDevice = fxDevice2; // // Drop the reference we got from QueryInterface(). Since this object // is partnered with the framework object they have the same // lifespan - there is no need for an additional reference. // fxDevice2->Release(); } return hr; }
HRESULT CDriver::OnDeviceAdd( __in IWDFDriver* pDriver, __in IWDFDeviceInitialize* pDeviceInit ) /*++ Routine Description: The framework calls this function when a device is being added to the driver stack. Arguments: IWDFDriver - Framework interface. The driver uses this interface to create device objects. IWDFDeviceInitialize - Framework interface. The driver uses this interface to set device parameters before creating the device obeject. Return Value: HRESULT S_OK - Device added successfully --*/ { IUnknown *pDeviceCallback = NULL; IWDFDevice *pIWDFDevice = NULL; IWDFDevice2 *pIWDFDevice2 = NULL; IUnknown *pIUnkQueue = NULL; // // UMDF Toaster is a function driver so set is as the power policy owner (PPO) // pDeviceInit->SetPowerPolicyOwnership(TRUE); // // Create our device callback object. // HRESULT hr = CDevice::CreateInstance(&pDeviceCallback); // // Ask the framework to create a device object for us. // We pass in the callback object and device init object // as creation parameters. // if (SUCCEEDED(hr)) { hr = pDriver->CreateDevice(pDeviceInit, pDeviceCallback, &pIWDFDevice); } // // Create the queue callback object. // if (SUCCEEDED(hr)) { hr = CQueue::CreateInstance(&pIUnkQueue); } // // Configure the default queue. We pass in our queue callback // object to inform the framework about the callbacks we want. // if (SUCCEEDED(hr)) { IWDFIoQueue * pDefaultQueue = NULL; hr = pIWDFDevice->CreateIoQueue( pIUnkQueue, TRUE, // bDefaultQueue WdfIoQueueDispatchParallel, TRUE, // bPowerManaged FALSE, // bAllowZeroLengthRequests &pDefaultQueue); SAFE_RELEASE(pDefaultQueue); } // // Enable the device interface. // if (SUCCEEDED(hr)) { hr = pIWDFDevice->CreateDeviceInterface(&GUID_DEVINTERFACE_TOASTER, NULL); } // // IWDFDevice2 interface is an extension of IWDFDevice interface that enables // Idle and Wake support. // // // Get a pointer to IWDFDevice2 interface // if (SUCCEEDED(hr)) { hr = pIWDFDevice->QueryInterface(__uuidof(IWDFDevice2), (void**) &pIWDFDevice2); } // // Since this is a virtual device we tell the framework that we cannot wake // ourself if we sleep in S0. Only way the device can be brought to D0 is if // the device recieves an I/O from the system. // if (SUCCEEDED(hr)) { hr = pIWDFDevice2->AssignS0IdleSettings( IdleCannotWakeFromS0, PowerDeviceD3, //the lowest-powered device sleeping state IDLEWAKE_TIMEOUT_MSEC, //idle timeout IdleAllowUserControl, //user can control the device's idle behavior. WdfTrue); } // // TODO: Add the Idle and Wake suupport specific for your hardware // SAFE_RELEASE(pDeviceCallback); SAFE_RELEASE(pIWDFDevice); SAFE_RELEASE(pIWDFDevice2); SAFE_RELEASE(pIUnkQueue); return hr; }