WetCode

Untitled

Dec 14th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <string>
  5. #include <algorithm>    // std::transform
  6. #include <Windows.h>
  7.  
  8. #pragma comment(lib, "Version.lib")
  9.  
  10. using namespace std;
  11.  
  12. struct LANGANDCODEPAGE {
  13.     WORD wLanguage;
  14.     WORD wCodePage;
  15. } *lpTranslate;
  16.  
  17. typedef struct {
  18.   WORD  wLength;
  19.   WORD  wValueLength;
  20.   WORD  wType;
  21.   WCHAR szKey;
  22.   WORD  Padding;
  23.   WORD  Value;
  24. } String;
  25.  
  26. typedef struct {
  27.   WORD  wLength;
  28.   WORD  wValueLength;
  29.   WORD  wType;
  30.   WCHAR szKey;
  31.   WORD  Padding;
  32.   DWORD Value;
  33. } Var;
  34.  
  35. typedef struct {
  36.   WORD  wLength;
  37.   WORD  wValueLength;
  38.   WORD  wType;
  39.   WCHAR szKey;
  40.   WORD  Padding;
  41.   Var   Children;
  42. } VarFileInfo;
  43.  
  44. typedef struct {
  45.   WORD   wLength;
  46.   WORD   wValueLength;
  47.   WORD   wType;
  48.   WCHAR  szKey;
  49.   WORD   Padding;
  50.   String Children;
  51. } StringTable;
  52.  
  53. typedef struct {
  54.   WORD             wLength;
  55.   WORD             wValueLength;
  56.   WORD             wType;
  57.   WCHAR            szKey;
  58.   WORD             Padding1;
  59.   VS_FIXEDFILEINFO Value;
  60.   WORD             Padding2;
  61.   WORD             Children;
  62. } VS_VERSIONINFO;
  63.  
  64. char* UnicodeToAnsi(LPCWSTR s)
  65. {
  66.     if (s==NULL) return NULL;
  67.     int cw=lstrlenW(s);
  68.     if (cw==0) {
  69.         char *psz = new CHAR[1];*psz='\0';
  70.         return psz;
  71.     }
  72.     int cc = WideCharToMultiByte(CP_ACP,0,s,cw,NULL,0,NULL,NULL);
  73.     if (cc==0)
  74.         return NULL;
  75.  
  76.     char *psz=new CHAR[cc+1];
  77.     cc=WideCharToMultiByte(CP_ACP,0,s,cw,psz,cc,NULL,NULL);
  78.     if (cc==0) {
  79.         delete[] psz;
  80.         return NULL;
  81.     }
  82.     psz[cc]='\0';
  83.     return psz;
  84. }
  85.  
  86. int main(int argc, char* argv[])
  87. {
  88.  
  89.  
  90.     cout << "Enter File Name: ";
  91.     string sFileName;
  92.     getline( cin, sFileName );
  93.  
  94.     cout << sFileName << endl;
  95.  
  96.     DWORD dummy;
  97.     DWORD dwSize = GetFileVersionInfoSize(sFileName.c_str(), &dummy);
  98.     if (dwSize == 0)
  99.     {
  100.         cout << "GetFileVersionInfoSize failed with error: " << GetLastError() << endl;
  101.         system("PAUSE");
  102.         return false;
  103.     }
  104.    
  105.     unsigned char * clpInfoBuffer = new unsigned char[ dwSize ]; // Buffer containing File Version Information
  106.     ZeroMemory( clpInfoBuffer, dwSize );
  107.    
  108.     // load the version info
  109.     if (!GetFileVersionInfoA(sFileName.c_str(), NULL, dwSize, clpInfoBuffer) )
  110.     {
  111.         cout << "GetFileVersionInfo failed with error: " << GetLastError() << endl;
  112.         system("PAUSE");
  113.         return false;
  114.     }
  115.  
  116.    
  117.     LANGANDCODEPAGE lpLangAndCodePage;
  118.     ZeroMemory( &lpLangAndCodePage, sizeof( LANGANDCODEPAGE ) );
  119.     unsigned unLandPageSize = 0;
  120.  
  121.     if ( !VerQueryValue( clpInfoBuffer, "\\VarFileInfo\\Translation", (LPVOID*)&lpLangAndCodePage, &unLandPageSize ) )
  122.     {
  123.         cout << "VerQueryValue \\VarFileInfo\\Translation - failed with error: " << GetLastError() << endl;
  124.         system("PAUSE");
  125.         return false;
  126.     }
  127.  
  128.     // Need language ID..... ? ?
  129.     cout << "Size Land and Code Page: " << unLandPageSize << endl;
  130.     cout << "Lang: " << lpLangAndCodePage.wLanguage << endl;
  131.     cout << "C Page: " << lpLangAndCodePage.wCodePage << endl;
  132.  
  133.     char *test = new char[ MAX_PATH ];
  134.     VerLanguageName( lpLangAndCodePage.wLanguage, test, MAX_PATH);
  135.     cout << "test: " << test << endl;
  136.  
  137.  
  138.  
  139.     system("PAUSE");
  140.     return 0;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment