简体   繁体   English

在 C# 中读取 PVOID,我应该读取多少位?

[英]Reading a PVOID in c#, how many bits should I read?

I'm reading from a USB packet that has a URB type.我正在读取具有 URB 类型的 USB 数据包。 The URB header defined at http://msdn.microsoft.com/en-us/library/windows/hardware/ff540409(v=vs.85).aspx ashttp://msdn.microsoft.com/en-us/library/windows/hardware/ff540409(v=vs.85).aspx定义的 URB 标头为

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

How many bits should I be reading for the PVOID?我应该为 PVOID 读取多少位?

Since that's a pointer type, then it depends on your platform.由于这是一种指针类型,因此它取决于您的平台。 32 bits for x86; x86 为 32 位; 64 bits for x64. x64 为 64 位。

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.当然,您需要知道该字段的大小才能到达正文。 :) :)

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.将根据操作系统正确提供指针的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM