I'm trying to retrieve a file description from a PE file using the following code:
//This code was simplified &
//most error checks were removed for brevity
BYTE* pData = new BYTE[4096];
LPCTSTR path = L"C:\\Windows\\system32\\Speech\\Engines\\TTS\\MSTTSEngine.dll";
if(::GetFileVersionInfo(path, NULL, 4096, pData))
{
struct LANGANDCODEPAGE
{
WORD wLanguage;
WORD wCodePage;
} *lpTranslate = NULL;
UINT cbTranslate;
if(VerQueryValue(pData, L"\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &cbTranslate))
{
CString strBlock;
strBlock.Format(L"\\StringFileInfo\\%04x%04x\\FileDescription",
lpTranslate[0].wLanguage,
lpTranslate[0].wCodePage
);
UINT dwProdLn = 0;
VOID* lpBufferName = NULL;
if(VerQueryValue(pData, strBlock, &lpBufferName, &dwProdLn))
{
TRACE(L"Description: %s", lpBufferName);
}
else
{
TRACE(L"Error=%d", ::GetLastError());
}
}
delete[] pData;
}
That specific file (here's the copy if you don't have it on your Windows 10) has the string table encoded with wLanguage
being 0 and wCodePage
being 1200. In that case VerQueryValue
fails with error code ERROR_RESOURCE_TYPE_NOT_FOUND
. But I know that that file has "file description" property when I check it in File Explorer:
So what am I doing wrong in my code above?