Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
getnativesysteminfo (kernel32)
 
.
Summary

C# Signature:

[DllImport("kernel32.dll")]
internal static extern void GetNativeSystemInfo(ref SYSTEM_INFO lpSystemInfo);

VB Signature:

Private Declare Sub GetNativeSystemInfo Lib "kernel32" (<MarshalAs(UnmanagedType.Struct)> ByRef lpSystemInfo As SYSTEM_INFO)

User-Defined Types:

SYSTEM_INFO

Alternative Unmanaged API:

GetSystemInfo

Notes:

This sample will determine is the os supports 64bit.

Tips & Tricks:

Please add some!

Sample Code:

    public enum Platform
    {
      X86,
      X64,
      IA64,
      Unknown
    }

    internal const ushort PROCESSOR_ARCHITECTURE_INTEL = 0;
    internal const ushort PROCESSOR_ARCHITECTURE_IA64 = 6;
    internal const ushort PROCESSOR_ARCHITECTURE_AMD64 = 9;
    internal const ushort PROCESSOR_ARCHITECTURE_UNKNOWN = 0xFFFF;

    [StructLayout(LayoutKind.Sequential)]
    internal struct SYSTEM_INFO
    {
      public ushort wProcessorArchitecture;
      public ushort wReserved;
      public uint dwPageSize;
      public IntPtr lpMinimumApplicationAddress;
      public IntPtr lpMaximumApplicationAddress;
      public UIntPtr dwActiveProcessorMask;
      public uint dwNumberOfProcessors;
      public uint dwProcessorType;
      public uint dwAllocationGranularity;
      public ushort wProcessorLevel;
      public ushort wProcessorRevision;
    };

    [DllImport("kernel32.dll")]
    internal static extern void GetNativeSystemInfo(ref SYSTEM_INFO lpSystemInfo);

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

    public static Platform GetPlatform()
    {
      SYSTEM_INFO sysInfo = new SYSTEM_INFO();

      if(System.Environment.OSVersion.Version.Major > 5 ||
    (System.Environment.OSVersion.Version.Major == 5 && System.Environment.OSVersion.Version.Minor >= 1))
      {
    GetNativeSystemInfo(ref sysInfo);
      }
      else
      {
    GetSystemInfo(ref sysInfo);
      }

      switch(sysInfo.wProcessorArchitecture)
      {
    case PROCESSOR_ARCHITECTURE_IA64:
      return Platform.IA64;

    case PROCESSOR_ARCHITECTURE_AMD64:
      return Platform.X64;

    case PROCESSOR_ARCHITECTURE_INTEL:
      return Platform.X86;

    default:
      return Platform.Unknown;
      }
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions