我有一个结构
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct SERVER_USB_DEVICE
{
USB_HWID usbHWID;
byte status;
bool bExcludeDevice;
bool bSharedManually;
ulong ulDeviceId;
ulong ulClientAddr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
string usbDeviceDescr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
string locationInfo;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
string nickName;
}
当我将它传递给 win32 DLL 函数时,如下所示:
[DllImport ("abc.dll", EntryPoint="EnumDevices", CharSet=CharSet.Ansi)]
public static extern bool EnumDevices(IntPtr lpUsbDevices,
ref ulong pulBufferSize,
IntPtr lpES);
我在结构的字符串成员中得到一些缺失的文本。
假设 SERVER_USB_DEVICE.usbDeviceDescr 包含值“Mass Storage Device”这是错误的,它应该包含值“USB Mass Storage Device”
代码有什么问题?