-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModulVer.cpp
More file actions
104 lines (89 loc) · 2.5 KB
/
ModulVer.cpp
File metadata and controls
104 lines (89 loc) · 2.5 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* RDNSLOGS 7.0
* Performs Reverse DNS lookups on multiple logfiles.
* This program is designed to work with the Analog Logfile analyzer.
*
* Supports compressed files
*
* Antonio C. Silvestri
* tonysilvestri@bytecodeman.com
*
***/
#include "ModulVer.h"
ModuleVersion::ModuleVersion()
{
m_pVersionInfo = NULL; // raw version info data
}
//////////////////
// Destroy: delete version info
//
ModuleVersion::~ModuleVersion()
{
delete [] m_pVersionInfo;
}
//////////////////
// Get file version info for a given module
// Allocates storage for all info, fills "this" with
// VS_FIXEDFILEINFO, and sets codepage.
//
bool ModuleVersion::GetFileVersionInfo(const char *modulename)
{
m_translation.charset = 1252; // default = ANSI code page
memset((VS_FIXEDFILEINFO*)this, 0, sizeof(VS_FIXEDFILEINFO));
// get module handle
char filename[_MAX_PATH];
HMODULE hModule = ::GetModuleHandle(modulename);
if (hModule==NULL && modulename!=NULL)
return false;
// get module file name
DWORD len = GetModuleFileName(hModule, filename, sizeof(filename)/sizeof(filename[0]));
if (len <= 0)
return false;
// read file version info
DWORD dwDummyHandle; // will always be set to zero
len = GetFileVersionInfoSize(filename, &dwDummyHandle);
if (len <= 0)
return false;
m_pVersionInfo = new BYTE[len]; // allocate version info
if (!::GetFileVersionInfo(filename, 0, len, m_pVersionInfo))
return false;
LPVOID lpvi;
UINT iLen;
if (!VerQueryValue(m_pVersionInfo, "\\", &lpvi, &iLen))
return false;
// copy fixed info to myself, which is derived from VS_FIXEDFILEINFO
*(VS_FIXEDFILEINFO*)this = *(VS_FIXEDFILEINFO*)lpvi;
// Get translation info
if (VerQueryValue(m_pVersionInfo,
"\\VarFileInfo\\Translation", &lpvi, &iLen) && iLen >= 4) {
m_translation = *(TRANSLATION*)lpvi;
}
return dwSignature == VS_FFI_SIGNATURE;
}
//////////////////
// Get string file info.
// Key name is something like "CompanyName".
// returns the value as a CString.
//
string ModuleVersion::GetValue(const char *key)
{
string sVal;
if (m_pVersionInfo) {
// To get a string value must pass query in the form
//
// "\StringFileInfo\<langID><codepage>\keyname"
//
// where <lang-codepage> is the languageID concatenated with the
// code page, in hex. Wow.
//
char query[256];
sprintf(query, "\\StringFileInfo\\%04x%04x\\%s", m_translation.langID,
m_translation.charset, key);
LPCTSTR pVal;
UINT iLenVal;
if (VerQueryValue(m_pVersionInfo, query, (LPVOID*)&pVal, &iLenVal)) {
sVal = pVal;
}
}
return sVal;
}