Created
April 25, 2015 00:46
-
-
Save MagnusTiberius/d5ecf74deb47dc548cd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DWORD GetFileVersionInfo3(const TCHAR *pszFilePath, std::vector<std::pair<std::wstring, std::wstring>> *lplist) | |
{ | |
DWORD dwSize = 0; | |
BYTE *pbVersionInfo = NULL; | |
VS_FIXEDFILEINFO *pFileInfo = NULL; | |
UINT puLenFileInfo = 0; | |
dwSize = GetFileVersionInfoSize(pszFilePath, NULL); | |
if (dwSize == 0) | |
{ | |
printf("\nError in GetFileVersionInfoSize: %d\n", GetLastError()); | |
return 1; | |
} | |
pbVersionInfo = new BYTE[dwSize]; | |
memset(pbVersionInfo, '\0', dwSize); | |
if (!GetFileVersionInfo(pszFilePath, 0, dwSize, pbVersionInfo)) | |
{ | |
printf("\nError in GetFileVersionInfo: %d\n", GetLastError()); | |
delete[] pbVersionInfo; | |
return 1; | |
} | |
if (!VerQueryValue(pbVersionInfo, TEXT("\\"), (LPVOID*)&pFileInfo, &puLenFileInfo)) | |
{ | |
printf("\nError in VerQueryValue: %d\n", GetLastError()); | |
delete[] pbVersionInfo; | |
return 1; | |
} | |
if (!VerQueryValue(pbVersionInfo, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &puLenFileInfo)) | |
{ | |
printf("\nError in VerQueryValue: %d\n", GetLastError()); | |
return 1; | |
} | |
std::vector<std::wstring>::iterator itr; | |
std::vector<std::wstring> wlist; | |
wlist.clear(); | |
wlist.push_back(L"FileDescription"); | |
wlist.push_back(L"InternalName"); | |
wlist.push_back(L"OriginalFilename"); | |
wlist.push_back(L"CompanyName"); | |
wlist.push_back(L"FileVersion"); | |
wlist.push_back(L"ProductName"); | |
wlist.push_back(L"ProductVersion"); | |
wlist.push_back(L"LegalCopyright"); | |
char fileEntry[1024]; | |
for (int i = 0; i < (puLenFileInfo / sizeof(struct LANGANDCODEPAGE)); i++) | |
{ | |
sprintf_s(fileEntry, 256, "\\StringFileInfo\\%04x%04x\\", | |
lpTranslate[i].wLanguage, | |
lpTranslate[i].wCodePage); | |
lplist->push_back(std::pair<std::wstring, std::wstring>(L"File: ", pszFilePath)); | |
std::string s1(fileEntry); | |
for (itr = wlist.begin(); itr != wlist.end(); itr++) | |
{ | |
std::wstring item = *itr; | |
std::wstring wstr; | |
wstr.append(s1.begin(), s1.end()); | |
wstr.append(item); | |
LPVOID lpBuffer = NULL; | |
UINT dwBytes = 0; | |
bool bRes = VerQueryValue(pbVersionInfo, wstr.c_str(), (LPVOID*)&lpBuffer, &dwBytes); | |
if (!bRes) | |
{ | |
continue; | |
} | |
LPTSTR wsResult; | |
wsResult = (LPTSTR)lpBuffer; | |
lplist->push_back(std::pair<std::wstring, std::wstring>(item, wsResult)); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment