accessing Double pointer
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;
struct {
UCHAR NumberConfiguredPipes;
WDFUSBINTERFACE ConfiguredUsbInterface;
} SingleInterface;
struct {
UCHAR NumberInterfaces;
PWDF_USB_INTERFACE_SETTING_PAIR Pairs;
UCHAR NumberOfConfiguredInterfaces;
} MultiInterface;
} 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
(*someIntDesc)->iInterface
IntDesc foo;
// somehow initialize foo to actually point to (a pointer to) a valid structure
(*foo)->iInterface = 10;
Deference it like this
(*intDesc)->iInterface
IntDesc is a type, not a variable. So the first thing you need to do is create a variable of the correct type:
IntDesc id;
Next, you'll need to have it point to allocated memory. I'm going to put everything on the stack, you may have other needs:
USB_INTERFACE_DESCRIPTOR usb;
PUSB_INTERFACE_DESCRIPTOR pusb = &usb;
id = &pusb;
Now that you have a valid pointer, you can go ahead an dereference it. Since this is a double pointer, you will need to dereference it twice:
(*(*id)).iInterface = 10;
Because C defines ->
as a combination of *
and .
, you can express that more succinctly with:
(*id)->iInterface = 10;
From the name InterfaceDescriptors
, it would appear to point to an array of pointers to the structure. So the more idiomatic way would be:
InterfaceDescriptors[0]->iInterface = 10;
Your code is quite wrong
NODE* ptr;
k.N.iInterface = 100;
ptr = (NODE*)malloc(sizeof(NODE));
And before accesing:
ptr->N1->iInterface
N1 should be initialized to something.
精彩评论