[英]Retrieve File Description for an Application using VerQueryValue
I am really confused with this function.我真的对这个功能感到困惑。 Currently I am successful in retrieving the
FileVersion
and ProductVersion
.目前我成功检索了
FileVersion
和ProductVersion
。 Now I want to retrieve more information within the application, like FileDescription
and CompanyName
.现在我想在应用程序中检索更多信息,例如
FileDescription
和CompanyName
。
DWORD dwLen;
VS_FIXEDFILEINFO *pFileInfo;
UINT pLenFileInfo;
dwLen = GetFileVersionInfoSize("D:/firefox.exe", NULL);
BYTE *sKey = new BYTE[dwLen];
GetFileVersionInfo("D:/firefox.exe", NULL, dwLen, sKey);
VerQueryValue(sKey, "\\", (LPVOID*)&pFileInfo, &pLenFileInfo);
// at now i can retrieve file Version with structure VS_FIXEDFILEINFO
VerQueryValue(sKey, "\\StringFileInfo\\%04x%09x\\FileDescription", (LPVOID*) &pFileInfo, &pLenFileInfo);
delete[] sKey;
cout << pFileInfo;
// it return address buffer `00230428`;
How exactly can I return the FileDescription
, like Firefox
?我究竟如何才能返回
FileDescription
,如Firefox
? What structure is used to retrieve the FileDescription
in the 3rd LPVOID
parameter?什么结构用于检索第三个
LPVOID
参数中的FileDescription
? In my code, I pass pFileInfo
twice into VerQueryValue()
.在我的代码中,我将
pFileInfo
两次传递给VerQueryValue()
。
EDIT:编辑:
DWORD dwLen;
struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
dwLen = GetFileVersionInfoSize("D:/firefox.exe", NULL);
BYTE *sKey = new BYTE[dwLen];
TCHAR *sCompanyName = new char[1024];
GetFileVersionInfo("D:/firefox.exe", NULL, dwLen, sKey);
VerQueryValue(sKey, "\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &pLenFileInfo);
VerQueryValue(test, "\\StringFileInfo\\%04x%09x\\FileDescription", (LPVOID*)&sCompanyName, &pLenFileInfo);
delete[] sKey;
cout << lpTranslate -> wLanguage;
VerQueryValue(test, "\\\\StringFileInfo\\\\%04x%09x\\\\FileDescription", (LPVOID*)&sCompanyName, &pLenFileInfo);
The second parameter should be of this format "\\\\StringFileInfo\\\\NxM\\\\FileDescription"
where N
and M
are wLanguage
and wCodePage
.第二个参数应该是
"\\\\StringFileInfo\\\\NxM\\\\FileDescription"
格式,其中N
和M
是wLanguage
和wCodePage
。 Following the example in comment section, you can use "%04x%04x"
as print format specifier to create a string.按照注释部分中的示例,您可以使用
"%04x%04x"
作为打印格式说明符来创建字符串。 Example:例子:
BOOL foo()
{
const char* filename = "c:\\windows\\hh.exe";
int dwLen = GetFileVersionInfoSize(filename, NULL);
if(!dwLen)
return 0;
auto *sKey = new BYTE[dwLen];
std::unique_ptr<BYTE[]> skey_automatic_cleanup(sKey);
if(!GetFileVersionInfo(filename, NULL, dwLen, sKey))
return 0;
struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
UINT cbTranslate = 0;
if(!VerQueryValue(sKey, "\\VarFileInfo\\Translation",
(LPVOID*)&lpTranslate, &cbTranslate))
return 0;
for(unsigned int i = 0; i < (cbTranslate / sizeof(LANGANDCODEPAGE)); i++)
{
char subblock[256];
//use sprintf if sprintf_s is not available
sprintf_s(subblock, "\\StringFileInfo\\%04x%04x\\FileDescription",
lpTranslate[i].wLanguage, lpTranslate[i].wCodePage);
char *description = NULL;
UINT dwBytes;
if(VerQueryValue(sKey, subblock, (LPVOID*)&description, &dwBytes))
MessageBox(0, description, 0, 0);
}
return TRUE;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.