Condividi tramite


Descrittori di stringhe USB

I descrittori di dispositivo, configurazione e interfaccia possono contenere riferimenti ai descrittori di stringa. Questo argomento descrive come ottenere un descrittore di stringa specifico dal dispositivo.

I descrittori di stringa fanno riferimento al relativo numero di indice in base uno. Un descrittore di stringa contiene una o più stringhe Unicode; ogni stringa è una traduzione degli altri in un'altra lingua.

Client drivers use UsbBuildGetDescriptorRequest, with DescriptorType = USB_STRING_DESCRIPTOR_TYPE, to build the request to obtain a string descriptor. The Index parameter specifies the index number, and the LanguageID parameter specifies the language ID (the same values are used as in Microsoft Win32 LANGID values). I driver possono richiedere il numero di indice speciale pari a zero per determinare gli ID lingua supportati dal dispositivo. Per questo valore speciale, il dispositivo restituisce una matrice di ID lingua anziché una stringa Unicode.

Poiché il descrittore di stringa è costituito da dati a lunghezza variabile, il driver deve ottenerlo in due passaggi. Prima di tutto, il driver deve emettere la richiesta, passando un buffer di dati sufficientemente grande da contenere l'intestazione per un descrittore di stringa, una struttura USB_STRING_DESCRIPTOR. The bLength member of USB_STRING_DESCRIPTOR specifies the size in bytes of the entire descriptor. The driver then makes the same request with a data buffer of size bLength.

The following code demonstrates how to request the i-th string descriptor, with language ID langID:

USB_STRING_DESCRIPTOR USD, *pFullUSD;
UsbBuildGetDescriptorRequest(
    pURB, // points to the URB to be filled in
    sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
    USB_STRING_DESCRIPTOR_TYPE,
    i, // index of string descriptor
    langID, // language ID of string.
    &USD, // points to a USB_STRING_DESCRIPTOR.
    NULL,
    sizeof(USB_STRING_DESCRIPTOR),
    NULL
);
pFullUSD = ExAllocatePool(NonPagedPool, USD.bLength);
UsbBuildGetDescriptorRequest(
    pURB, // points to the URB to be filled in
    sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
    USB_STRING_DESCRIPTOR_TYPE,
    i, // index of string descriptor
    langID, // language ID of string
    pFullUSD,
    NULL,
    USD.bLength,
    NULL
);