Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #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;
- char* UnicodeToAnsi(LPCWSTR s)
- {
- if (s==NULL) return NULL;
- int cw=lstrlenW(s);
- if (cw==0) {
- char *psz = new CHAR[1];*psz='\0';
- return psz;
- }
- int cc = WideCharToMultiByte(CP_ACP,0,s,cw,NULL,0,NULL,NULL);
- if (cc==0)
- return NULL;
- char *psz=new CHAR[cc+1];
- cc=WideCharToMultiByte(CP_ACP,0,s,cw,psz,cc,NULL,NULL);
- if (cc==0) {
- delete[] psz;
- return NULL;
- }
- psz[cc]='\0';
- return psz;
- }
- 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( lpLangAndCodePage.wLanguage, test, MAX_PATH);
- cout << "test: " << test << endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment