Accessing a structure variable double pointer

£可爱£侵袭症+ 提交于 2020-01-06 08:46:11

问题


Some code:

typedef struct _WDF_USB_DEVICE_SELECT_CONFIG_PARAMS { 
ULONG Size;
WdfUsbTargetDeviceSelectConfigType Type;
union {   
     struct {
     PUSB_CONFIGURATION_DESCRIPTOR  ConfigurationDescriptor;
     PUSB_INTERFACE_DESCRIPTOR*  InterfaceDescriptors;
     ULONG NumInterfaceDescriptors;
     } Descriptor;

     struct {
     PURB  Urb;
     } Urb;
   } Types;

} WDF_USB_DEVICE_SELECT_CONFIG_PARAMS,*PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS; WDF_USB_DEVICE_SELECT_CONFIG_PARAMS params;

typedef struct _USB_INTERFACE_DESCRIPTOR {
UCHAR bLength ;
UCHAR bInterfaceClass ;
UCHAR bInterfaceSubClass ;
} USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR ;

Able to acess NumInterfaceDescriptors via -> params.Types.Descriptor.NumInterfaceDescriptors

I want to acess bInterfaceClass via WDF_USB_DEVICE_SELECT_CONFIG_PARAMS . Please note that this structure is filled by the library I have to just access it


回答1:


It appears that what you want is:

ULONG iface;

for (iface = 0; iface < params.Types.Descriptor.NumInterfaceDescriptors; iface++)
{
    do_something_with(params.Types.Descriptor.InterfaceDescriptors[iface]);
}

..but you should really put some more time into making your questions clear so that people don't have to guess what you mean.




回答2:


Google for WDF_USB_DEVICE_SELECT_CONFIG_PARAMS. The first hit leads you to the relevant MSDN page, which tells you that Types.Descriptor.InterfaceDescriptors

contains a driver-supplied pointer to an array of USB_INTERFACE_DESCRIPTOR structures

and that Types.Descriptor.NumInterfaceDescriptors indeed

contains the number of elements that are in the interface array that Types.Descriptor.InterfaceDescriptors points to.

Ergo, your "pointer to pointer" is actually an array of USB_INTERFACE_DESCRIPTOR pointers.



来源:https://stackoverflow.com/questions/2085761/accessing-a-structure-variable-double-pointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!