GetSystemInfo (kernel32)
Last changed: Milkenm-65.49.2.17

.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);

User-Defined Types:

None.

Notes:

This API mapping demonstrates mapping a union in C#.

Tips & Tricks:

Please add some!

Sample Code:

using System;

using System.Runtime.InteropServices;

namespace TestGetSystemInfo

{

    public class WinApi
    {
    [DllImport("kernel32.dll")]
    public static extern void GetSystemInfo([MarshalAs(UnmanagedType.Struct)] ref SYSTEM_INFO lpSystemInfo);

    [StructLayout(LayoutKind.Sequential)]
    public struct SYSTEM_INFO
    {
        internal _PROCESSOR_INFO_UNION uProcessorInfo;
        public uint dwPageSize;
        public uint lpMinimumApplicationAddress;
        public uint lpMaximumApplicationAddress;
        public uint dwActiveProcessorMask;
        public uint dwNumberOfProcessors;
        public uint dwProcessorType;
        public uint dwAllocationGranularity;
        public uint dwProcessorLevel;
        public uint dwProcessorRevision;
    }

    [StructLayout(LayoutKind.Explicit)]
    public struct _PROCESSOR_INFO_UNION
    {
        [FieldOffset(0)]
        internal uint dwOemId;
        [FieldOffset(0)]
        internal ushort wProcessorArchitecture;
        [FieldOffset(2)]
        internal ushort wReserved;
    }
    }

    public class Program
    {
    public static void Main(string[] args)
    {
        WinApi.SYSTEM_INFO sysinfo = new WinApi.SYSTEM_INFO();
        WinApi.GetSystemInfo(ref sysinfo);
        Console.WriteLine("dwProcessorType ={0}", sysinfo.dwProcessorType.ToString());
        Console.WriteLine("dwPageSize      ={0}", sysinfo.dwPageSize.ToString());
    }
    }

}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation