acmilan作者
10年6个月前修改于 10年6个月前IP:四川
821141
1楼

对于和一般的WinAPI交互来说,没必要这么麻烦,可以使用StructLayout和MarshalAs解决:

using 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);
        }
    }
}
评论
文号 / 821141

千古风流
名片发私信
学术分 4
总主题 466 帖总回复 2942 楼拥有证书:进士 学者 笔友
注册于 2009/05/30 21:22:42最后登录 2019/01/31 17:16:38
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:0

个人简介

暂未填写
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的