How to traverse a multi-language version resource?

不羁岁月 提交于 2019-12-08 09:45:47

问题


I'm trying to use the code snippet shown at the end of this page to read multi-language version resource for executable files.

But, for example, when I run the code below for this file:

I get my nCnt as 1 for only one resource, i.e. English.

What am I doing wrong?

LPCTSTR buff = L"path-to\\file.exe";

struct LANGANDCODEPAGE {
  WORD wLanguage;
  WORD wCodePage;
} *lpTranslate;

DWORD dwDummy;
DWORD dwSz = GetFileVersionInfoSize(buff, &dwDummy);
if(dwSz > 0)
{
    BYTE* pData = new (std::nothrow)BYTE[dwSz];
    if(pData)
    {
        if(GetFileVersionInfo(buff, NULL, dwSz, pData))
        {
            //Get language info
            UINT ncbSz;
            LANGANDCODEPAGE* pLcp;
            if(VerQueryValue(pData, L"\\VarFileInfo\\Translation", (VOID**)&pLcp, &ncbSz))
            {
                UINT nCnt = ncbSz / sizeof(struct LANGANDCODEPAGE);

                CString strQuery;
                UINT nczBufLn;
                LPCTSTR pDescBuf;

                for(UINT i = 0; i < nCnt; i++)
                {
                    strQuery.Format(L"\\StringFileInfo\\%04x%04x\\FileDescription", 
                        pLcp[i].wLanguage, pLcp[i].wCodePage);
                    if(VerQueryValue(pData, (LPTSTR)strQuery.GetString(), (VOID**)&pDescBuf, &nczBufLn))
                    {
                        wprintf(L"Description%d: %s\n", i, pDescBuf);
                    }
                }
            }
        }

        delete[] pData;
    }
}

回答1:


There are two ways to store multi-language version resources.

The best way is of course to have one resource entry with multiple translation blocks. These will be accessible with VerQueryValue.

The other way is to store multiple resource entries, one for each language. This is the way you store other types of localized resources (bitmaps, strings etc.). EnumResourceLanguages should be able to enumerate them but GetFileVersionInfo will probably just pick the language that matches your thread or UI language.



来源:https://stackoverflow.com/questions/47441124/how-to-traverse-a-multi-language-version-resource

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!