void GetVersionOfFile (char * pszAppName, // file char * pszVerBuff, // receives version int iVerBuffLen, // size of buffer char * pszLangBuff, // receives language int iLangBuffLen) // size of buffer { DWORD dwScratch; DWORD * pdwLangChar; DWORD dwInfSize ; UINT uSize; BYTE * pbyInfBuff; char szVersion [32]; char szResource [80]; char * pszVersion = szVersion;
dwInfSize = GetFileVersionInfoSize (pszAppName, &dwScratch);
if (dwInfSize) { pbyInfBuff = new BYTE [dwInfSize]; memset (pbyInfBuff, 0, dwInfSize); if (pbyInfBuff) { if (GetFileVersionInfo (pszAppName, 0, dwInfSize, pbyInfBuff)) { if (VerQueryValue (pbyInfBuff, "\\VarFileInfo\\Translation", (void**)(&pdwLangChar), &uSize)) { if (VerLanguageName (LOWORD (*pdwLangChar), szResource, sizeof(szResource))) { strncpy (pszLangBuff, szResource, iLangBuffLen); } wsprintf (szResource, "\\StringFileInfo\\%04X%04X\\FileVersion", LOWORD (*pdwLangChar), HIWORD (*pdwLangChar));
if (VerQueryValue (pbyInfBuff, szResource, (void**)(&pszVersion), &uSize)) { strncpy (pszVerBuff, pszVersion, iVerBuffLen-1); } } } delete [] pbyInfBuff; } } } |