views:

54

answers:

1

I'm trying to get information about a Windows Mobile device from a desktop application (written in C#). I searched the MSDN and found that the function I need is in rapi.dll:

VOID CeGetSystemInfo (LPSYSTEM_INFO lpSystemInfo);

The parameter is a pointer to a struct which is deffined like this:

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;

Here is how I mapped it all to managed code:

[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;
}

When I call the function passing the SYSTEM_INFO struct nothing happens. The function does not alter the values of the struct in any way. Have I mapped the struct wrong or something?

Thanks in advance

A: 

Got it!

The rapi.dll needs to be initialized by calling the CeRapiInit function and then after all your function calls you need to close the rapi by calling CeRapiUinit

Raphael