Created
July 11, 2017 08:42
-
-
Save hide1202/865f75dff30a04c926f3ec40c4b770b1 to your computer and use it in GitHub Desktop.
윈도우 버전 가져오기 (Get Windows OS Version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <tchar.h> | |
#include <Windows.h> | |
#pragma comment(lib, "version") | |
static void print_version() | |
{ | |
DWORD buffer_size = GetFileVersionInfoSize(_T("kernel32.dll"), NULL); | |
if (buffer_size == 0) | |
{ | |
// get error from GetLastError() | |
return; | |
} | |
VOID *buffer = malloc(buffer_size); | |
if (buffer == NULL) | |
{ | |
// out of memory | |
return; | |
} | |
if (!GetFileVersionInfo(_T("kernel32.dll"), 0, buffer_size, buffer)) | |
{ | |
goto error; | |
} | |
VS_FIXEDFILEINFO *version = NULL; | |
UINT version_len = 0; | |
if (!VerQueryValue(buffer, | |
_T("\\"), | |
(LPVOID*)&version, | |
&version_len)) | |
{ | |
goto error; | |
} | |
_tprintf(_T("Version is: %u.%u\n"), | |
HIWORD(version->dwProductVersionMS), | |
LOWORD(version->dwProductVersionMS)); | |
error: | |
free(buffer); | |
} | |
int main() | |
{ | |
print_version(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment