Statistics
| Branch: | Revision:

root / src / utils / opp_pefileversion.cc @ master

History | View | Annotate | Download (1.16 KB)

1 01873262 Georg Kunz
//
2
// Utility to detect MS Visual C++ version, and return it in the exit code
3
//
4
5
#pragma once
6
7
#ifndef _WIN32_WINNT
8
#define _WIN32_WINNT 0x0501
9
#endif
10
11
#include <stdio.h>
12
#include <tchar.h>
13
#include <windows.h>
14
15
int _tmain(int argc, _TCHAR* argv[])
16
{
17
    if (argc < 2)
18
    {
19
        printf("error: missing argument\n");
20
        return 0;
21
    }
22
23
    DWORD dwHandle = 0;
24
    DWORD dwSize = GetFileVersionInfoSize(argv[1], /*out*/ &dwHandle);
25
    if (dwSize == 0)
26
    {
27
        printf("error: file not found or no version info in file\n");
28
        return 0;
29
    }
30
    void* pData = malloc(dwSize);
31
    BOOL result = GetFileVersionInfo(argv[1], dwHandle, dwSize, pData);
32
    if (!result)
33
    {
34
        printf("error: cannot get version info from file\n");
35
        free(pData);
36
        return 0;
37
    }
38
    VS_FIXEDFILEINFO* pVerInfo = NULL;
39
    UINT nLen = 0;
40
    result = VerQueryValue(pData, _T("\\"), /*out*/ (void**)&pVerInfo, /*out*/ &nLen);
41
    if (!result)
42
    {
43
        printf("error: cannot query version info\n");
44
        free(pData);
45
        return 0;
46
    }
47
    WORD version = HIWORD(pVerInfo->dwFileVersionMS);
48
    free(pData);
49
    printf("%d\n", version);
50
    return version;
51
}