Windowsのプライマリ・バージョン番号、セカンダリ・バージョン、buildバージョン番号を取得

1193 ワード

#include

//-------------------------------------------------------------------------
//      : GetNtVersionNumbers
//      :  RtlGetNtVersionNumbers 
//    : 
//      : LOBYTE(LOWORD(dwVersion))  
//      : HIBYTE(LOWORD(dwVersion))  
//      : HIWORD(dwVersion)		  build 
//      :
//-------------------------------------------------------------------------
DWORD GetNtVersionNumbers()
{
    DWORD dwVersion = 0;
    HMODULE hModNtdll= NULL;
    TCHAR szBuffer[100];
    DWORD dwMajorVer, dwMinorVer, dwBuildNumber;
    if (hModNtdll= LoadLibrary(TEXT("ntdll.dll")))
    {
        typedef void (WINAPI *RtlGetNtVersionNumbers)(DWORD*,DWORD*, DWORD*);
        RtlGetNtVersionNumbers pfRtlGetNtVersionNumbers;
        pfRtlGetNtVersionNumbers = (RtlGetNtVersionNumbers)GetProcAddress(hModNtdll, "RtlGetNtVersionNumbers");
        if (pfRtlGetNtVersionNumbers)
        {
		pfRtlGetNtVersionNumbers(&dwMajorVer, &dwMinorVer,&dwBuildNumber);
		dwBuildNumber &= 0xffff;
        }
	dwVersion = MAKELONG(MAKEWORD(dwMajorVer,dwMinorVer),dwBuildNumber);
        FreeLibrary(hModNtdll);
    }
    return dwVersion;
}