Main Page | Class List | File List | Class Members | File Members

versioninfo.cpp

Go to the documentation of this file.
00001 // VersionInfo.cpp
00002 
00003 #include "VersionInfo.h"
00004 #include <windows.h>
00005 
00006 std::string GetModuleVersionInfo(const char* pszPath, const char* pszResource)
00007 {
00008   std::string s;
00009   char szPath[_MAX_PATH];
00010   szPath[0] = '\0';
00011   strncat(szPath, pszPath, sizeof(szPath)-1);
00012   DWORD dwBuffSize = GetFileVersionInfoSize(szPath, 0);
00013   LPVOID pszBuff = new char[dwBuffSize];
00014   LPSTR  lpInfo;
00015   if (GetFileVersionInfo(szPath, 0, dwBuffSize, pszBuff))
00016   {
00017     struct LANGANDCODEPAGE {
00018       WORD wLanguage;
00019       WORD wCodePage;
00020     } *lpTranslate;
00021     UINT cbTranslate;
00022     // Read the first language and code page
00023     VerQueryValue(pszBuff, 
00024                   TEXT("\\VarFileInfo\\Translation"),
00025                   (LPVOID*)&lpTranslate,
00026                   &cbTranslate);
00027     char szSubBlock[512];
00028     for( UINT i=0; i < (cbTranslate/sizeof(struct LANGANDCODEPAGE)); i++ )
00029     {
00030       _snprintf(szSubBlock, sizeof(szSubBlock),
00031         "\\StringFileInfo\\%04x%04x\\%s",
00032         lpTranslate[i].wLanguage,
00033         lpTranslate[i].wCodePage,
00034         pszResource);
00035       UINT dwBytes;
00036       if (VerQueryValue(pszBuff, szSubBlock, (LPVOID*)&lpInfo, &dwBytes))
00037       {
00038         s = lpInfo;
00039         break;
00040       }
00041     }
00042   }
00043   delete[]pszBuff;
00044   return s;
00045 }
00046 
00047 std::string GetVersionInfo(const char* pszResource)
00048 {
00049   char szPath[_MAX_PATH];
00050   szPath[0] = '\0';
00051   std::string s;
00052   if (GetModuleFileName(NULL, szPath, sizeof(szPath)))
00053     s = GetModuleVersionInfo(szPath, pszResource);
00054   return s;
00055 }
00056 
00057 std::string GetProductInfo()
00058 {
00059   std::string sProductName = GetVersionInfo("ProductName");
00060   std::string sVersion = GetVersionInfo("ProductVersion");
00061   return sProductName + " " + sVersion;
00062 }

Generated on Sun Jun 26 13:43:46 2005 for pingem by  doxygen 1.4.3