我正在尝试从桌面应用程序(用 C# 编写)获取有关 Windows Mobile 设备的信息。我搜索了MSDN,发现我需要的函数在rapi.dll中:
VOID CeGetSystemInfo (LPSYSTEM_INFO lpSystemInfo);
参数是指向结构的指针,其定义如下:
typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO, *LPSYSTEM_INFO;
这是我将其全部映射到托管代码的方式:
[DllImport("rapi.dll")]
public static extern void CeGetSystemInfo([MarshalAs(UnmanagedType.Struct)]ref SYSTEM_INFO info);
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
internal PROCESSOR_INFO_UNION uProcessorInfo;
public uint dwPageSize;
public IntPtr lpMinimumApplicationAddress;
public IntPtr lpMaximumApplicationAddress;
public uint dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public ushort wProcessorLevel;
public ushort wProcessorRevision;
}
[StructLayout(LayoutKind.Explicit)]
public struct PROCESSOR_INFO_UNION
{
[FieldOffset(0)]
internal uint dwOemId;
[FieldOffset(1)]
internal ushort wProcessorArchitecture;
[FieldOffset(2)]
internal ushort wReserved;
}
当我调用传递 SYSTEM_INFO 结构的函数时,没有任何反应。该函数不会以任何方式更改结构的值。我映射结构错误还是什么?
提前致谢