HRESULT CMyDevice::OnPrepareHardware( _In_ IWDFDevice * /* FxDevice */ ) /*++ Routine Description: This routine is invoked to ready the driver to talk to hardware. It opens the handle to the device and talks to it using the WINUSB interface. It invokes WINUSB to discver the interfaces and stores the information related to bulk endpoints. Arguments: FxDevice : Pointer to the WDF device interface Return Value: HRESULT --*/ { PWSTR deviceName = NULL; DWORD deviceNameCch = 0; HRESULT hr; // // Get the device name. // Get the length to allocate first // hr = m_FxDevice->RetrieveDeviceName(NULL, &deviceNameCch); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get device name %!hresult!", hr ); } // // Allocate the buffer // if (SUCCEEDED(hr)) { deviceName = new WCHAR[deviceNameCch]; if (deviceName == NULL) { hr = E_OUTOFMEMORY; } } // // Get the actual name // if (SUCCEEDED(hr)) { hr = m_FxDevice->RetrieveDeviceName(deviceName, &deviceNameCch); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get device name %!hresult!", hr ); } } if (SUCCEEDED(hr)) { TraceEvents(TRACE_LEVEL_INFORMATION, TEST_TRACE_DEVICE, "%!FUNC! Device name %S", deviceName ); } // // Create USB I/O Targets and configure them // if (SUCCEEDED(hr)) { hr = CreateUsbIoTargets(); } if (SUCCEEDED(hr)) { ULONG length = sizeof(m_Speed); hr = m_pIUsbTargetDevice->RetrieveDeviceInformation(DEVICE_SPEED, &length, &m_Speed); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get usb device speed information %!HRESULT!", hr ); } } if (SUCCEEDED(hr)) { TraceEvents(TRACE_LEVEL_INFORMATION, TEST_TRACE_DEVICE, "%!FUNC! Speed - %x\n", m_Speed ); } delete[] deviceName; return hr; }
HRESULT CMyDevice::OnPrepareHardware( __in IWDFDevice * /* FxDevice */ ) /*++ Routine Description: This routine is invoked to ready the driver to talk to hardware. It opens the handle to the device and talks to it using the WINUSB interface. It invokes WINUSB to discver the interfaces and stores the information related to bulk endpoints. Arguments: FxDevice : Pointer to the WDF device interface Return Value: HRESULT --*/ { PWSTR deviceName = NULL; DWORD deviceNameCch = 0; HRESULT hr; // // Get the device name. // Get the length to allocate first // hr = m_FxDevice->RetrieveDeviceName(NULL, &deviceNameCch); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get device name %!HRESULT!", hr ); } // // Allocate the buffer // if (SUCCEEDED(hr)) { deviceName = new WCHAR[deviceNameCch]; if (deviceName == NULL) { hr = E_OUTOFMEMORY; } } // // Get the actual name // if (SUCCEEDED(hr)) { hr = m_FxDevice->RetrieveDeviceName(deviceName, &deviceNameCch); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get device name %!HRESULT!", hr ); } } if (SUCCEEDED(hr)) { TraceEvents(TRACE_LEVEL_INFORMATION, TEST_TRACE_DEVICE, "%!FUNC! Device name %S", deviceName ); } // // Create USB I/O Targets and configure them // if (SUCCEEDED(hr)) { hr = CreateUsbIoTargets(); } if (SUCCEEDED(hr)) { ULONG length = sizeof(m_Speed); hr = m_pIUsbTargetDevice->RetrieveDeviceInformation(DEVICE_SPEED, &length, &m_Speed); if (FAILED(hr)) { TraceEvents(TRACE_LEVEL_ERROR, TEST_TRACE_DEVICE, "%!FUNC! Cannot get usb device speed information %!HRESULT!", hr ); } } if (SUCCEEDED(hr)) { TraceEvents(TRACE_LEVEL_INFORMATION, TEST_TRACE_DEVICE, "%!FUNC! Speed - %x\n", m_Speed ); } if (SUCCEEDED(hr)) { hr = ConfigureUsbPipes(); } // // Setup power-management settings on the device. // if (SUCCEEDED(hr)) { hr = SetPowerManagement(); } // // Clear the seven segement display to indicate that we're done with // prepare hardware. // if (SUCCEEDED(hr)) { hr = IndicateDeviceReady(); } #if defined(_NOT_POWER_POLICY_OWNER_) // // We have non-power managed queues, so we Stop them in OnReleaseHardware // and start them in OnPrepareHardware // if (SUCCEEDED(hr)) { m_ReadWriteQueue->Start(); m_ControlQueue->Start(); } #endif if (SUCCEEDED(hr)) { hr = ConfigContReaderForInterruptEndPoint(); } delete[] deviceName; return hr; }