本文介绍了使用 VerQueryValue 检索应用程序的文件描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的对这个功能感到困惑.目前我成功检索了 FileVersionProductVersion.现在我想在应用程序中检索更多信息,例如 FileDescriptionCompanyName.

I am really confused with this function. Currently I am successful in retrieving the FileVersion and ProductVersion. Now I want to retrieve more information within the application, like FileDescription and 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`;

我怎样才能返回 FileDescription,比如 Firefox?什么结构用于检索第三个 LPVOID 参数中的 FileDescription?在我的代码中,我将 pFileInfo 两次传递给 VerQueryValue().

How exactly can I return the FileDescription, like Firefox? What structure is used to retrieve the FileDescription in the 3rd LPVOID parameter? In my code, I pass pFileInfo twice into VerQueryValue().

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);

第二个参数应该是这种格式 "\\StringFileInfo\\NxM\\FileDescription" 其中 NM>wLanguagewCodePage.按照注释部分的示例,您可以使用 "%04x%04x" 作为打印格式说明符来创建字符串.示例:

The second parameter should be of this format "\\StringFileInfo\\NxM\\FileDescription" where N and M are wLanguage and wCodePage. Following the example in comment section, you can use "%04x%04x" as print format specifier to create a string. 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;
}

这篇关于使用 VerQueryValue 检索应用程序的文件描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 13:39