Windows Driver Development-3

Source: Internet
Author: User

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.