This repository was archived by the owner on May 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathversion.cpp
More file actions
58 lines (44 loc) · 1.23 KB
/
Copy pathversion.cpp
File metadata and controls
58 lines (44 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* GSD
*
* Copyright (C) 2008 mosa Ÿe5bW6vDOJ. <pcyp4g@gmail.com>
*
* This is free software with ABSOLUTELY NO WARRANTY.
*
* You can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License.
*
*/
#include <windows.h>
#include <winver.h>
#include "version.h"
#pragma comment(lib, "version.lib")
bool ReadVersionFile(LPCTSTR szFileName, sVersionInfo *info)
{
bool bRet = false;
DWORD cbBlock = GetFileVersionInfoSize(szFileName, 0);
if(cbBlock){
BYTE *pbBlock = new BYTE [cbBlock];
if(GetFileVersionInfo(szFileName, 0, cbBlock, (LPVOID)pbBlock)){
LPVOID pvBuf = NULL;
UINT uLen = 0;
if(VerQueryValue((const LPVOID)pbBlock, "\\", &pvBuf, &uLen)){
VS_FIXEDFILEINFO *pvfi = (VS_FIXEDFILEINFO *)pvBuf;
info->word.wVer1 = HIWORD(pvfi->dwFileVersionMS);
info->word.wVer2 = LOWORD(pvfi->dwFileVersionMS);
info->word.wVer3 = HIWORD(pvfi->dwFileVersionLS);
info->word.wVer4 = LOWORD(pvfi->dwFileVersionLS);
bRet = true;
}
}
delete [] pbBlock;
}
return bRet;
}
bool ReadVersionModule(HMODULE hModule, sVersionInfo *info)
{
TCHAR szPath[MAX_PATH];
if(GetModuleFileName(hModule, szPath, MAX_PATH))
return ReadVersionFile(szPath, info);
return false;
}