airmax: (Default)
[personal profile] airmax

// will run on win2000+
#define _WIN32_WINNT 0x0500

#include <windows.h>

extern "C"
{
typedef BOOL (__stdcall* ISWOW64PROC) (HANDLE, PBOOL);
}

TCHAR* GetWinVerStr()
{
	static TCHAR szWinVers[256];

	OSVERSIONINFOEX osVersion;
	memset(&osVersion, 0, sizeof(osVersion));
	osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	if (!GetVersionEx((OSVERSIONINFO*)&osVersion))
	{
		memset(&osVersion, 0, sizeof(osVersion));
		osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 
		if (!GetVersionEx((OSVERSIONINFO*)&osVersion))
		{
			return NULL;
		}
	}

	TCHAR chFlag;
	if (osVersion.dwOSVersionInfoSize == sizeof(OSVERSIONINFOEX))
	{
		if (osVersion.wSuiteMask == VER_SUITE_PERSONAL)
		{
			chFlag = 'h';
		} else if (osVersion.wSuiteMask == VER_SUITE_DATACENTER)
		{
			chFlag = 'd';
		} else if (osVersion.wSuiteMask == VER_SUITE_ENTERPRISE)
		{
			chFlag = 'e';
		} else if (osVersion.wSuiteMask == VER_SUITE_BLADE)
		{
			chFlag = 'w';
		} else if (osVersion.wSuiteMask == VER_SUITE_SMALLBUSINESS)
		{
			chFlag = 's';
		} else if (osVersion.wSuiteMask == VER_SUITE_TERMINAL)
		{
			chFlag = 't';
		} else {
			chFlag = ' ';
		}
	} else
		chFlag = '-';

	const TCHAR* szWinPlatform = 
	((osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) ? TEXT("Win9x") : 
	 (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) ? TEXT("WinNT") : 
	 (osVersion.dwPlatformId == VER_PLATFORM_WIN32s) ? TEXT("Win31") : 
	 TEXT("Win??")
	);

	ISWOW64PROC fIsW64 = (ISWOW64PROC)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), TEXT("IsWow64Process"));
	if (fIsW64 != NULL)
	{
		BOOL isWow64;
		if ((fIsW64(GetCurrentProcess(), &isWow64) != 0) && isWow64)
		{
			szWinPlatform = TEXT("Wow64");
		}
	}

	wsprintf(szWinVers, TEXT("%s %u.%u.%u %u.%u%c%s"), szWinPlatform,
		osVersion.dwMajorVersion,
		osVersion.dwMinorVersion,
		LOWORD(osVersion.dwBuildNumber),
		osVersion.wServicePackMajor,
		osVersion.wServicePackMinor,
		chFlag,
		osVersion.szCSDVersion
		);
	
	return szWinVers;
}


int main(int argc, char* argv[])
{
	MessageBox(NULL, GetWinVerStr(), TEXT("Windows version"), MB_ICONINFORMATION);
	return 0;
}

Profile

airmax: (Default)
airmax

April 2011

S M T W T F S
      12
345 6 7 89
10 11 12 131415 16
17181920212223
24252627282930

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 6th, 2026 01:00 pm
Powered by Dreamwidth Studios