裝置、組態和介面描述元可能包含字串描述元的參考。 本主題說明如何從裝置取得特定字串描述元。
字串描述子由其從一開始的索引號碼所參照。 字串描述子包含一或多個 Unicode 字串;每個字串都是其他字串翻譯成另一種語言。
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). 驅動程式可以要求特殊索引號碼零,以判斷裝置支援哪些語言標識碼。 針對這個特殊值,裝置會傳回語言識別碼陣列,而不是 Unicode 字串。
因為字串描述元是由可變長度資料所組成,所以驅動程式必須以兩個步驟取得它。 首先,驅動程式必須發出要求,傳遞足夠大的數據緩衝區,以保留字串描述元的標頭,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
);