0

我正在尝试从桌面应用程序(用 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 结构的函数时,没有任何反应。该函数不会以任何方式更改结构的值。我映射结构错误还是什么?

提前致谢

4

1 回答 1

0

知道了!

rapi.dll 需要通过调用 CeRapiInit 函数来初始化,然后在所有函数调用之后,您需要通过调用 CeRapiUinit 来关闭 rapi

于 2010-02-10T15:37:58.080 回答