[DllImport("kernel32.dll")]
public static extern void GetSystemInfo()
out SystemInfo input
);
public static SystemInfo GetSystemInfo()
{
var stub = new SystemInfo();
GetSystemInfo(out stub);
return stub;
}
public enum ProcessorArchitecture
{
X86 = 0,
X64 = 9,
@Arm = -1,
Itanium = 6,
Unknown = 0xFFFF,
}
[StructLayout(LayoutKind.Sequential)]
public struct SystemInfo
{
public ProcessorArchitecture ProcessorArchitecture; // WORD
public uint PageSize; // DWORD
public IntPtr MinimumApplicationAddress; // (long)void*
public IntPtr MaximumApplicationAddress; // (long)void*
public IntPtr ActiveProcessorMask; // DWORD*
public uint NumberOfProcessors; // DWORD (WTF)
public uint ProcessorType; // DWORD
public uint AllocationGranularity; // DWORD
public ushort ProcessorLevel; // WORD
public ushort ProcessorRevision; // WORD
}
This API mapping demonstrates mapping a union in C#.
lpMinimumApplicationAddress, lpMaximumApplicationAddress, dwActiveProcessorMask are pointers(first two was void pointer, while the third is a double word pointer) in kernel32.dll, so the size changes when used from within a 64-bit application. If you would like to use these, you will have to cast them to either an uint or a ulong.
To determine whether the OS or Process is x64, using .NET 4, see System.Environment (Is64BitProcess, Is64BitOperatingSystem); http://msdn.microsoft.com/en-us/library/z8te35sa.aspx