EDITED: Retriving File Description and other data.

So this code try to retrieve the language identifying string of the version info and then get the file description for that file. Using resource Hacker I can get the value "080904B0" but trying to get the value with the API I have not manage to do.

The example on MSDN has been to weary little help with this part.
Do anyone of you seasoned programmers here have any ideas as this is a bit puzzling to me.

Here is the code I have been working on.
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <string>
#include <algorithm>    // std::transform
#include <Windows.h>

#pragma comment(lib, "Version.lib")

using namespace std;

struct LANGANDCODEPAGE {
	WORD wLanguage;
	WORD wCodePage;
} *lpTranslate;

typedef struct {
  WORD  wLength;
  WORD  wValueLength;
  WORD  wType;
  WCHAR szKey;
  WORD  Padding;
  WORD  Value;
} String;

typedef struct {
  WORD  wLength;
  WORD  wValueLength;
  WORD  wType;
  WCHAR szKey;
  WORD  Padding;
  DWORD Value;
} Var;

typedef struct {
  WORD  wLength;
  WORD  wValueLength;
  WORD  wType;
  WCHAR szKey;
  WORD  Padding;
  Var   Children;
} VarFileInfo;

typedef struct {
  WORD   wLength;
  WORD   wValueLength;
  WORD   wType;
  WCHAR  szKey;
  WORD   Padding;
  String Children;
} StringTable;

typedef struct {
  WORD             wLength;
  WORD             wValueLength;
  WORD             wType;
  WCHAR            szKey;
  WORD             Padding1;
  VS_FIXEDFILEINFO Value;
  WORD             Padding2;
  WORD             Children;
} VS_VERSIONINFO;

int main(int argc, char* argv[])
{


	cout << "Enter File Name: ";
	string sFileName;
	getline( cin, sFileName );

	cout << sFileName << endl;

    DWORD dummy;
	DWORD dwSize = GetFileVersionInfoSize(sFileName.c_str(), &dummy);
    if (dwSize == 0)
    {
        cout << "GetFileVersionInfoSize failed with error: " << GetLastError() << endl;
		system("PAUSE");
        return false;
    }
	
	unsigned char * clpInfoBuffer = new unsigned char[ dwSize ]; // Buffer containing File Version Information
	ZeroMemory( clpInfoBuffer, dwSize );
	
    // load the version info
	if (!GetFileVersionInfoA(sFileName.c_str(), NULL, dwSize, clpInfoBuffer) )
    {
        cout << "GetFileVersionInfo failed with error: " << GetLastError() << endl;
		system("PAUSE");
        return false;
    }

	
	LANGANDCODEPAGE lpLangAndCodePage;
	ZeroMemory( &lpLangAndCodePage, sizeof( LANGANDCODEPAGE ) );
	unsigned unLandPageSize = 0;

	if ( !VerQueryValue( clpInfoBuffer, "\\VarFileInfo\\Translation", (LPVOID*)&lpLangAndCodePage, &unLandPageSize ) )
	{
        cout << "VerQueryValue \\VarFileInfo\\Translation - failed with error: " << GetLastError() << endl;
		system("PAUSE");
        return false;
	}

	// Need language ID..... ? ? 
	cout << "Size Land and Code Page: " << unLandPageSize << endl;
	cout << "Lang: " << lpLangAndCodePage.wLanguage << endl;
	cout << "C Page: " << lpLangAndCodePage.wCodePage << endl;

	char *test = new char[ MAX_PATH ];
	VerLanguageName( (DWORD)lpLangAndCodePage.wLanguage, test, MAX_PATH); 
	// Always returns with string "Language Nuetral"
	
	cout << "test: " << test << endl;
	string sLangString(test);

	delete []test;
	test = nullptr;
	
	cout << "STRING: " << sLangString << endl;
	string sGetInfoStr = "\\StringFileInfo\\";
	sGetInfoStr.append( "080904B0" ); 
	// if i do it like this sGetInfoStr.append( sLangString ); 
	 /*  i get error 1813 ERROR_RESOURCE_TYPE_NOT_FOUND
             1813 (0x715)
			The specified resource type cannot be found in the image file. */

	sGetInfoStr.append( "\\FileDescription");

	test = new char[ MAX_PATH ];
	unsigned unLandDescStrSize = 0;

	if ( !VerQueryValue( clpInfoBuffer, sGetInfoStr.c_str(), (LPVOID*)&test, &unLandDescStrSize ) )
	{
        cout << "VerQueryValue " << sGetInfoStr.c_str() << " - failed with error: " << GetLastError() << endl;
		system("PAUSE");
        return false;
	}

	cout << "Description: " << test << endl; // works with value from Resource Hacker

	test = nullptr;
	system("PAUSE");
	return 0;
}
Last edited on
Topic archived. No new replies allowed.