UfxDeviceNotifyAttach 函数 (ufxclient.h)
通知 UFX 设备的 USB 电缆已连接。
语法
void UfxDeviceNotifyAttach(
[in] UFXDEVICE UfxDevice
);
参数
[in] UfxDevice
驱动程序通过调用 UfxDeviceCreate 创建的 UFX 设备对象的句柄。
返回值
无
备注
当客户端驱动程序调用 UfxDeviceNotifyAttach 时,USB 函数类扩展 (UFX) 执行以下操作:
- 将设备移动到 USB 规范中定义的供电状态。
- 允许进行设备枚举。
客户端驱动程序通常从其EVT_WDF_INTERRUPT_DPC回调函数调用 UfxDeviceNotifyAttach,如以下示例所示。
VOID
DeviceInterrupt_EvtInterruptDpc (
_In_ WDFINTERRUPT Interrupt,
_In_ WDFOBJECT AssociatedObject
)
/*++
Routine Description:
'EVT_WDF_INTERRUPT_DPC' handler for the device interrupt object.
Arguments:
Interrupt - Associated interrupt object.
AssociatedObject - FDO Object
--*/
{
WDFDEVICE WdfDevice;
PDEVICE_INTERRUPT_CONTEXT InterruptContext;
PCONTROLLER_CONTEXT ControllerContext;
BOOLEAN Attached;
BOOLEAN GotAttachOrDetach;
CONTROLLER_EVENT ControllerEvent;
UNREFERENCED_PARAMETER(Interrupt);
TraceEntry();
WdfDevice = (WDFDEVICE) AssociatedObject;
ControllerContext = DeviceGetControllerContext(WdfDevice);
WdfSpinLockAcquire(ControllerContext->DpcLock);
WdfInterruptAcquireLock(ControllerContext->DeviceInterrupt);
Attached = ControllerContext->Attached;
GotAttachOrDetach = ControllerContext->GotAttachOrDetach;
ControllerContext->GotAttachOrDetach = FALSE;
WdfInterruptReleaseLock(ControllerContext->DeviceInterrupt);
//
// Handle attach/detach events
//
if (GotAttachOrDetach) {
if (Attached && ControllerContext->WasAttached) {
//
// We must have gotten at least one detach. Need to reset the state.
//
ControllerContext->RemoteWakeupRequested = FALSE;
ControllerContext->Suspended = FALSE;
UfxDeviceNotifyDetach(ControllerContext->UfxDevice);
}
if (Attached) {
ControllerContext->RemoteWakeupRequested = FALSE;
ControllerContext->Suspended = FALSE;
UfxDeviceNotifyAttach(ControllerContext->UfxDevice);
}
}
ControllerContext->WasAttached = Attached;
InterruptContext = DeviceInterruptGetContext(ControllerContext->DeviceInterrupt);
//
// #### TODO: Insert code to read and dispatch events from the controller ####
//
// The sample will assume an endpoint event of EndpointEventTransferComplete
ControllerEvent.Type = EventTypeEndpoint;
ControllerEvent.u.EndpointEvent = EndpointEventTransferComplete;
//
// Handle events from the controller
//
switch (ControllerEvent.Type) {
case EventTypeDevice:
HandleDeviceEvent(WdfDevice, ControllerEvent.u.DeviceEvent);
break;
case EventTypeEndpoint:
HandleEndpointEvent(WdfDevice, ControllerEvent.u.EndpointEvent);
break;
}
WdfSpinLockRelease(ControllerContext->DpcLock);
TraceExit();
}
要求
要求 | 值 |
---|---|
最低受支持的客户端 | Windows 10 |
目标平台 | Windows |
标头 | ufxclient.h |
Library | ufxstub.lib |
IRQL | DISPATCH_LEVEL |