UfxDeviceCreate 函数 (ufxclient.h)
创建 UFX 设备对象,注册事件回调例程,并指定特定于控制器的功能。
语法
NTSTATUS UfxDeviceCreate(
WDFDEVICE WdfDevice,
[in] PUFX_DEVICE_CALLBACKS Callbacks,
[in] PUFX_DEVICE_CAPABILITIES Capabilities,
[in, optional] PWDF_OBJECT_ATTRIBUTES Attributes,
[out] UFXDEVICE *UfxDevice
);
参数
WdfDevice
WDF 设备对象的句柄。
[in] Callbacks
UFX_DEVICE_CALLBACKS 类型的结构,包含指向要与 UFX 设备对象关联的驱动程序提供的回调例程的指针。
[in] Capabilities
指向 UFX_DEVICE_CAPABILITIES 结构的指针。
[in, optional] Attributes
指向 WDF_OBJECT_ATTRIBUTES 结构的指针,该结构包含新对象的驱动程序提供的属性。 此参数是可选的,可以 WDF_NO_OBJECT_ATTRIBUTES。
[out] UfxDevice
指向接收新 UFX 设备对象的句柄的位置的指针。
返回值
如果操作成功,该方法将返回STATUS_SUCCESS或NT_SUCCESS (状态) 等于 TRUE 的另一个状态值。 否则,它将返回一个状态值,NT_SUCCESS (状态) 等于 FALSE。
注解
客户端驱动程序必须先调用 WdfDeviceCreate ,然后才能调用 UfxDeviceCreate。 通常,客户端驱动程序从其 EvtDriverDeviceAdd 回调例程调用 UfxDeviceCreate。
以下代码片段演示如何调用 UfxDeviceCreate。
NTSTATUS
UfxDevice_DeviceCreate (
_In_ WDFDEVICE WdfDevice
)
/*++
Routine Description:
Routine that registers with UFX and creates the UFX device object.
Arguments:
WdfDevice - Wdf object representing the device.
Return Value:
NTSTATUS.
--*/
{
NTSTATUS Status;
PCONTROLLER_CONTEXT ControllerContext;
UFX_DEVICE_CALLBACKS UfxDeviceCallbacks;
UFX_DEVICE_CAPABILITIES UfxDeviceCapabilities;
PUFXDEVICE_CONTEXT UfxDeviceContext;
UFXDEVICE UfxDevice;
WDF_OBJECT_ATTRIBUTES Attributes;
PAGED_CODE();
TraceEntry();
ControllerContext = DeviceGetControllerContext(WdfDevice);
UFX_DEVICE_CAPABILITIES_INIT(&UfxDeviceCapabilities);
UfxDeviceCapabilities.MaxSpeed = UsbSuperSpeed;
UfxDeviceCapabilities.RemoteWakeSignalDelay = REMOTE_WAKEUP_TIMEOUT_INTERVAL_MS;
//
// Set bitmasks that define the IN and OUT endpoint numbers that are available on the controller
//
//
// #### TODO: Set the IN endpoint mask here if not all endpoint addresses are supported ####
//
// For illustration purposes sample will set default control endpoint 0, 1-4, 8
UfxDeviceCapabilities.InEndpointBitmap = 0x011F;
//
// #### TODO: Set the OUT endpoint mask here if not all endpoint addresses are supported ####
//
// For illustration purposes sample will set default control endpoint 0, 2-7
//
UfxDeviceCapabilities.OutEndpointBitmap = 0x00FD;
//
// Set the event callbacks for the ufxdevice
//
UFX_DEVICE_CALLBACKS_INIT(&UfxDeviceCallbacks);
UfxDeviceCallbacks.EvtDeviceHostConnect = UfxDevice_EvtDeviceHostConnect;
UfxDeviceCallbacks.EvtDeviceHostDisconnect = UfxDevice_EvtDeviceHostDisconnect;
UfxDeviceCallbacks.EvtDeviceAddressed = UfxDevice_EvtDeviceAddressed;
UfxDeviceCallbacks.EvtDeviceEndpointAdd = UfxDevice_EvtDeviceEndpointAdd;
UfxDeviceCallbacks.EvtDeviceDefaultEndpointAdd = UfxDevice_EvtDeviceDefaultEndpointAdd;
UfxDeviceCallbacks.EvtDeviceUsbStateChange = UfxDevice_EvtDeviceUsbStateChange;
UfxDeviceCallbacks.EvtDevicePortChange = UfxDevice_EvtDevicePortChange;
UfxDeviceCallbacks.EvtDevicePortDetect = UfxDevice_EvtDevicePortDetect;
UfxDeviceCallbacks.EvtDeviceRemoteWakeupSignal = UfxDevice_EvtDeviceRemoteWakeupSignal;
UfxDeviceCallbacks.EvtDeviceTestModeSet = UfxDevice_EvtDeviceTestModeSet;
UfxDeviceCallbacks.EvtDeviceSuperSpeedPowerFeature = UfxDevice_EvtDeviceSuperSpeedPowerFeature;
// Context associated with UFXDEVICE object
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&Attributes, UFXDEVICE_CONTEXT);
Attributes.EvtCleanupCallback = UfxDevice_EvtCleanupCallback;
// Create the UFXDEVICE object
Status = UfxDeviceCreate(WdfDevice,
&UfxDeviceCallbacks,
&UfxDeviceCapabilities,
&Attributes,
&UfxDevice);
...
}
要求
要求 | 值 |
---|---|
最低受支持的客户端 | Windows 10 |
目标平台 | Windows |
标头 | ufxclient.h |
Library | ufxstub.lib |
IRQL | PASSIVE_LEVEL |