Condividi tramite


Metodo IWDFUsbTargetDevice::FormatRequestForControlTransfer (wudfusb.h)

[Avviso: UMDF 2 è la versione più recente di UMDF e sostituisce UMDF 1. Tutti i nuovi driver UMDF devono essere scritti usando UMDF 2. Nessuna nuova funzionalità viene aggiunta a UMDF 1 ed è disponibile un supporto limitato per UMDF 1 nelle versioni più recenti di Windows 10. I driver di Windows universali devono usare UMDF 2. Per altre informazioni, vedere Introduzione con UMDF.]

Il metodo FormatRequestForControlTransfer formatta un oggetto richiesta di I/O per un trasferimento di controllo USB.

Sintassi

HRESULT FormatRequestForControlTransfer(
  [in]           IWDFIoRequest        *pRequest,
  [in]           PWINUSB_SETUP_PACKET SetupPacket,
  [in, optional] IWDFMemory           *pMemory,
  [in, optional] PWDFMEMORY_OFFSET    TransferOffset
);

Parametri

[in] pRequest

Puntatore all'interfaccia IWDFIoRequest per il formato dell'oggetto request.

[in] SetupPacket

Puntatore a un WINUSB_SETUP_PACKET per il trasferimento del controllo.

[in, optional] pMemory

Puntatore all'interfaccia IWDFMemory usata per accedere al buffer usato per il trasferimento del controllo. Questo parametro è facoltativo e,

[in, optional] TransferOffset

Puntatore a una struttura WDFMEMORY_OFFSET che descrive l'offset di memoria utilizzato per il trasferimento del controllo. Questo parametro è facoltativo e,

Valore restituito

FormatRequestForControlTransfer restituisce uno dei valori seguenti:

Codice restituito Descrizione
S_OK

FormatRequestForControlTransfer ha formattato correttamente un oggetto richiesta di I/O.

E_OUTOFMEMORY

FormatRequestForControlTransfer ha rilevato un errore di allocazione.

E_INVALIDARG
Offset di memoria specificato dal parametro TransferOffset non valido.

Commenti

Dopo che un driver UMDF chiama FormatRequestForControlTransfer per formattare una richiesta di I/O per un'operazione di trasferimento del controllo, il framework può successivamente inviare la richiesta alla destinazione di I/O.

Esempio

L'esempio di codice seguente viene tratto dall'esempio di wdf_osrfx2_lab in WDK.

    WINUSB_CONTROL_SETUP_PACKET setupPacket;

    ULONG bytesTransferred;

    HRESULT hr = S_OK;

    //
    // Setup the control packet.
    //

    WINUSB_CONTROL_SETUP_PACKET_INIT( &setupPacket,
                                      BmRequestHostToDevice,
                                      BmRequestToDevice,
                                      USBFX2LK_SET_BARGRAPH_DISPLAY,
                                      0,
                                      0 );

    //
    // Issue the request to WinUsb.
    //

    hr = SendControlTransferSynchronously(
                &(setupPacket.WinUsb),
                (PUCHAR) BarGraphState,
                sizeof(BAR_GRAPH_STATE),
                &bytesTransferred
                );
...

HRESULT
CMyDevice::SendControlTransferSynchronously(
    _In_ PWINUSB_SETUP_PACKET SetupPacket,
    _Inout_updates_(BufferLength) PBYTE Buffer,
    _In_ ULONG BufferLength,
    _Out_ PULONG LengthTransferred
    )
{
    HRESULT hr = S_OK;
    IWDFIoRequest *pWdfRequest = NULL;
    IWDFDriver * FxDriver = NULL;
    IWDFMemory * FxMemory = NULL; 
    IWDFRequestCompletionParams * FxComplParams = NULL;
    IWDFUsbRequestCompletionParams * FxUsbComplParams = NULL;

    *LengthTransferred = 0;
    
    hr = m_FxDevice->CreateRequest( NULL, //pCallbackInterface
                                    NULL, //pParentObject
                                    &pWdfRequest);

    if (SUCCEEDED(hr))
    {
        m_FxDevice->GetDriver(&FxDriver);

        hr = FxDriver->CreatePreallocatedWdfMemory( Buffer,
                                                    BufferLength,
                                                    NULL, //pCallbackInterface
                                                    pWdfRequest, //pParetObject
                                                    &FxMemory );
    }

    if (SUCCEEDED(hr))
    {
        hr = m_pIUsbTargetDevice->FormatRequestForControlTransfer( pWdfRequest,
                                                                   SetupPacket,
                                                                   FxMemory,
                                                                   NULL); //TransferOffset
    }                                                          
      

Requisiti

Requisito Valore
Fine del supporto Non disponibile in UMDF 2.0 e versioni successive.
Piattaforma di destinazione Desktop
Versione UMDF minima 1.5
Intestazione wudfusb.h (include Wudfusb.h)
DLL WUDFx.dll

Vedi anche

IWDFIoRequest

IWDFMemory

IWDFUsbTargetDevice

WDFMEMORY_OFFSET