| 36 | #pragma comment(lib, "version.lib") |
| 37 | |
| 38 | bool |
| 39 | GetProductVersionInfo(wstring& strProductName, wstring& strProductVersion, |
| 40 | wstring& strLegalCopyright, HMODULE hMod) |
| 41 | { |
| 42 | |
| 43 | TCHAR fullPath[MAX_PATH + 1]; |
| 44 | *fullPath = L'\0'; |
| 45 | if (!GetModuleFileName(hMod, fullPath, MAX_PATH)) { |
| 46 | return false; |
| 47 | } |
| 48 | DWORD dummy = 0; |
| 49 | DWORD vSize = GetFileVersionInfoSize(fullPath, &dummy); |
| 50 | if (vSize < 1) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | auto pVersionResourceHandle = cppcryptfs::unique_rsc(malloc, free, vSize); |
| 55 | |
| 56 | void* pVersionResource = pVersionResourceHandle.get(); |
| 57 | |
| 58 | if (pVersionResource == NULL) |
| 59 | { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | if (!GetFileVersionInfo(fullPath, NULL, vSize, pVersionResource)) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | // get the name and version strings |
| 68 | LPVOID pvProductName = NULL; |
| 69 | unsigned int iProductNameLen = 0; |
| 70 | LPVOID pvProductVersion = NULL; |
| 71 | unsigned int iProductVersionLen = 0; |
| 72 | LPVOID pvLegalCopyright = NULL; |
| 73 | unsigned int iLegalCopyrightLen = 0; |
| 74 | |
| 75 | struct LANGANDCODEPAGE { |
| 76 | WORD wLanguage; |
| 77 | WORD wCodePage; |
| 78 | } *lpTranslate; |
| 79 | |
| 80 | // Read the list of languages and code pages. |
| 81 | unsigned int cbTranslate; |
| 82 | if (!VerQueryValue(pVersionResource, |
| 83 | TEXT("\\VarFileInfo\\Translation"), |
| 84 | (LPVOID*)&lpTranslate, |
| 85 | &cbTranslate)) { |
| 86 | |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | if (cbTranslate / sizeof(struct LANGANDCODEPAGE) < 1) { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | wstring lang; |
| 95 |
no test coverage detected