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 |
目標平臺 | 窗戶 |
標頭 | ufxclient.h |
連結庫 | ufxstub.lib |
IRQL | DISPATCH_LEVEL |