对于和一般的WinAPI交互来说,没必要这么麻烦,可以使用StructLayout和MarshalAs解决:
Otherusing System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication5
{
class Program
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct RtlOSVersionInfoExW
{
public uint dwOSVersionInfoSize;
public uint dwMajorVersion;
public uint dwMinorVersion;
public uint dwBuildNumber;
public uint dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
public ushort wServicePackMajor;
public ushort wServicePackMinor;
public ushort wSuiteMask;
public byte wProductType;
public byte wReserved;
}
[DllImport("ntdll.dll")]
public static extern bool RtlGetVersion(ref RtlOSVersionInfoExW osver);
static void Main(string[] args)
{
RtlOSVersionInfoExW osvex = new RtlOSVersionInfoExW();
osvex.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osvex);
RtlGetVersion(ref osvex);
Console.WriteLine(osvex.dwMajorVersion);
Console.WriteLine(osvex.dwMinorVersion);
Console.WriteLine(osvex.dwBuildNumber);
Console.WriteLine(osvex.dwPlatformId);
Console.WriteLine(osvex.szCSDVersion);
Console.WriteLine(osvex.wServicePackMajor);
Console.WriteLine(osvex.wServicePackMinor);
Console.WriteLine(osvex.wSuiteMask);
Console.WriteLine(osvex.wProductType);
Console.WriteLine(osvex.wReserved);
}
}
}
200字以内,仅用于支线交流,主线讨论请采用回复功能。