vc的结构问题
typedef struct _SP_DEVINFO_DATA {
DWORD cbSize;
GUID ClassGuid;
DWORD DevInst;
ULONG_PTR Reserved;
} SP_DEVINFO_DATA, *PSP_DEVINFO_DATA;
在vc中sizeof取得结构的大小是28。
转换到c#中
[StructLayout(LayoutKind.Sequential)]
public class SP_DEVINFO_DATA
{
public UInt32 cbSize;
public Guid ClassGuid;
public UInt32 DevInst;
public ulong Reserved;
};
SP_DEVINFO_DATA spData = new SP_DEVINFO_DATA();
spData.cbSize = (UInt32)System.Runtime.InteropServices.Marshal.SizeOf(spData);
大小为什么变成了32?
------解决方案--------------------ref:
http://www.pinvoke.net/default.aspx/setupapi/SetupDiEnumDeviceInfo.html