Windows 驱动开发 - 3
2015-05-25 09:48
134 查看
上篇《Windows 驱动开发 - 2》我们已经添加了EvtDevicePrepareHardware事件,但是我们还没有增加内容。
对于USB来说主要进行2步操作:
初始化WDF_USB_DEVICE_SELECT_CONFIG_PARAMS结构变量地址。
附:代码(EvtDevicePrepareHardware事件)
对于USB来说主要进行2步操作:
1. 建立USB目标
使用方法WdfUsbTargetDeviceCreate来建立USB设备。NTSTATUS WdfUsbTargetDeviceCreate( [in] WDFDEVICE Device, [in, optional] PWDF_OBJECT_ATTRIBUTES Attributes, [out] WDFUSBDEVICE *UsbDevice );
(1) Context
为了针对USB设备,我们需要建立一个带USBDEVICE成员的结构指针。typedef struct _DEVICE_CONTEXT { WDFUSBDEVICE UsbDevice; WDFUSBINTERFACE UsbInterface; } DEVICE_CONTEXT, *PDEVICE_CONTEXT;
(2) Create Usb
status = WdfUsbTargetDeviceCreate(Device, WDF_NO_OBJECT_ATTRIBUTES, &pDeviceContext->UsbDevice);
2. 配置他
使用WdfUsbTargetDeviceSelectConfig方法来配置usb设备。NTSTATUS WdfUsbTargetDeviceSelectConfig( [in] WDFUSBDEVICE UsbDevice, [in, optional] PWDF_OBJECT_ATTRIBUTES PipeAttributes, [in, out] PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params );
(1) 初始化USB配置
使用WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACEVOID WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE( _Out_ PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params );
初始化WDF_USB_DEVICE_SELECT_CONFIG_PARAMS结构变量地址。
WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE(&configParams);
(2) 完成配置
status = WdfUsbTargetDeviceSelectConfig(pDeviceContext->UsbDevice, WDF_NO_OBJECT_ATTRIBUTES, &configParams);
附:代码(EvtDevicePrepareHardware事件)
NTSTATUS
EvtDevicePrepareHardware(
IN WDFDEVICE Device,
IN WDFCMRESLIST ResourceList,
IN WDFCMRESLIST ResourceListTranslated
)
{
NTSTATUS status;
PDEVICE_CONTEXT pDeviceContext;
WDF_USB_DEVICE_SELECT_CONFIG_PARAMS configParams;
UNREFERENCED_PARAMETER(ResourceList);
UNREFERENCED_PARAMETER(ResourceListTranslated);
pDeviceContext = GetDeviceContext(Device);
//
// Create the USB device if it is not already created.
//
if (pDeviceContext->UsbDevice == NULL) {
status = WdfUsbTargetDeviceCreate(Device, WDF_NO_OBJECT_ATTRIBUTES, &pDeviceContext->UsbDevice);
if (!NT_SUCCESS(status)) {
KdPrint(("WdfUsbTargetDeviceCreate failed 0x%x\n", status));
return status;
}
}
WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE(&configParams);
status = WdfUsbTargetDeviceSelectConfig(pDeviceContext->UsbDevice, WDF_NO_OBJECT_ATTRIBUTES, &configParams);
if(!NT_SUCCESS(status)) {
KdPrint(("WdfUsbTargetDeviceSelectConfig failed 0x%x\n", status));
return status;
}
pDeviceContext->UsbInterface =
configParams.Types.SingleInterface.ConfiguredUsbInterface;
return status;
}
相关文章推荐
- Windows文件系统过滤驱动开发教程
- WINDOWS 7 配置驱动开发环境(wdk7.60)
- Windows 驱动开发基础(九)内核函数
- Window XP驱动开发(十九) windows内核高级调试技巧(双机调试)
- Windows驱动开发WDM (5)- DeviceIoControl(直接方式交互"输出buffer")
- Windows的驱动开发模型
- Windows 7驱动开发系列(五)--WDM驱动设计原则
- windows驱动开发,界面开发
- Windows驱动开发WDM (9)- StartIO例程(串行化处理IRP)
- Windows驱动开发(1) - 驱动程序结构
- Windows驱动开发的一些资源下载记录
- Windows 文件系统过滤驱动开发教程 (第二版)
- <学习笔记>Windows驱动开发技术详解__派遣函数
- Windows驱动开发
- [Windows驱动开发](二)Windows驱动程序环境搭配(VS2010 + WDK + VirtualDDK + VMware)
- windows驱动开发——基础知识
- (转载)Windows文件系统过滤驱动开发教程
- 【Windows内核驱动开发】——读取注册表
- Windows文件系统过滤驱动开发教程
- Windows文件系统过滤驱动开发教程(2)