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 |
程式庫 | ufxstub.lib |
IRQL | DISPATCH_LEVEL |