CeGetSystemInfo不填充引用传递的结构

时间:2010-02-10 15:09:54

标签: c# windows-mobile pinvoke windows-ce rapi

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

提前致谢

1 个答案:

答案 0 :(得分:0)

知道了!

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