GetVersionEx by using kernel32.dll : Native Windows Function « Windows « C# / CSharp Tutorial






using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public class OSVersionInfo
{
    public int dwOSVersionInfoSize;
    public int dwMajorVersion;
    public int dwMinorVersion;
    public int dwBuildNumber;
    public int dwPlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
    public String szCSDVersion;
}


class MainClass
{
    [DllImport("kernel32.dll")]
    public static extern bool GetVersionEx([In, Out] OSVersionInfo osvi);

    static void Main(string[] args)
    {
        OSVersionInfo osvi = new OSVersionInfo();
        osvi.dwOSVersionInfoSize = Marshal.SizeOf(osvi);

        GetVersionEx(osvi);

        Console.WriteLine("Class size: " + osvi.dwOSVersionInfoSize);
        Console.WriteLine("Major Version: " + osvi.dwMajorVersion);
        Console.WriteLine("Minor Version: " + osvi.dwMinorVersion);
        Console.WriteLine("Build Number: " + osvi.dwBuildNumber);
        Console.WriteLine("Platform Id: " + osvi.dwPlatformId);
        Console.WriteLine("CSD Version: " + osvi.szCSDVersion);
        Console.WriteLine("Platform: " + Environment.OSVersion.Platform);
        Console.WriteLine("Version: " + Environment.OSVersion.Version);

    }
}
Class size: 148
Major Version: 5
Minor Version: 1
Build Number: 2600
Platform Id: 2
CSD Version: Service Pack 2
Platform: Win32NT
Version: 5.1.2600.131072








29.10.Native Windows Function
29.10.1.Calling Native DLL Functions
29.10.2.Calling a Function with a Structure Parameter
29.10.3.Enumerate Display Monitors
29.10.4.Get Workstation information
29.10.5.Get Computer name (char * parameter)
29.10.6.Get free disk space
29.10.7.Use native windows function to read file
29.10.8.The windows version information
29.10.9.Get current Active Window
29.10.10.Writing INI file: Write Private Profile String
29.10.11.Reading INI file: Get Private Profile String
29.10.12.GetVersionEx by using kernel32.dll
29.10.13.Get computer name (StringBuilder parameter)
29.10.14.Lock work station
29.10.15.Get Monitor Information