3

I'm reading from a USB packet that has a URB type. The URB header defined at http://msdn.microsoft.com/en-us/library/windows/hardware/ff540409(v=vs.85).aspx as

 struct _URB_HEADER {
    USHORT      Length;
    USHORT      Function;
    USBD_STATUS Status;
    PVOID       UsbdDeviceHandle;
    ULONG       UsbdFlags;
 };

How many bits should I be reading for the PVOID?

3
  • 1
    I am going to guess you should be sending a value the same size as Handle which would be determined by the operating system. Oct 6, 2011 at 13:38
  • 1
    give this article a read: Marshaling Opaque Pointers: a Special Case
    – balexandre
    Oct 6, 2011 at 13:40
  • 4
    32 or 64, depending on the bitness of the process. It is IntPtr in managed code. Oct 6, 2011 at 13:43

2 Answers 2

2

Since that's a pointer type, then it depends on your platform. 32 bits for x86; 64 bits for x64.

I'm not well-versed with those libraries but should you be using those fields though? The link you shared says "Reserved. Do not use".

Edit: Disregard the last statement. I just realized that the structure is just the header. Of course you need to know that field's size in order to get to the body. :)

2

Thanks for the comments - reading through them, it looks like using

 byte [] ptr_bytes = rdr.ReadBytes(System.IntPtr.Size);

will provide the size of the pointer correctly depending on the operating system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.