"Windows Driver Development-2" We have added the Evtdevicepreparehardware event, but we haven't added anything yet.
For USB, the main 2-step operation:
1. Setting up a USB target
Use the method wdfusbtargetdevicecreate to set up the USB device.
NTSTATUS wdfusbtargetdevicecreate ( [in] wdfdevice Device, [in, optional] pwdf_object_attributes Attributes, [out] wdfusbdevice *usbdevice);
(1) Context
To target a USB device, we need to create a struct pointer with a Usbdevice member.
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. Configure he uses the Wdfusbtargetdeviceselectconfig method to configure the USB device.
NTSTATUS Wdfusbtargetdeviceselectconfig ( [in] wdfusbdevice usbdevice, [in, optional] pwdf_object_ ATTRIBUTES pipeattributes, [in, out] pwdf_usb_device_select_config_params PARAMS);
(1) Initializing USB configuration using Wdf_usb_device_select_config_params_init_single_interface
VOID wdf_usb_device_select_config_params_init_single_interface ( _out_ pwdf_usb_device_select_config_params Params);
Initializes the address of the WDF_USB_DEVICE_SELECT_CONFIG_PARAMS structure variable.
Wdf_usb_device_select_config_params_init_single_interface (&configparams);
(2) Complete the configuration
Status = Wdfusbtargetdeviceselectconfig (Pdevicecontext->usbdevice, wdf_no_object_attributes, & Configparams);
Attached: Code (Evtdevicepreparehardware event)
Ntstatusevtdevicepreparehardware (in Wdfdevice Device, in Wdfcmreslist resourcelist, in Wdfcmreslist ResourceL isttranslated) {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 Driver Development-3