如何遍历多语言版本资源? [英] How to traverse a multi-language version resource?

查看:28
本文介绍了如何遍历多语言版本资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用显示的代码片段

我将 nCnt 设为 1 仅用于一种资源,即英语.

我做错了什么?

LPCTSTR buff = L"path-to\\file.exe";结构语言代码页{WORD 语言;WORD wCodePage;} *lp翻译;DWORD dwDummy;DWORD dwSz = GetFileVersionInfoSize(buff, &dwDummy);如果(dwSz > 0){BYTE* pData = new (std::nothrow)BYTE[dwSz];如果(pData){if(GetFileVersionInfo(buff, NULL, dwSz, pData)){//获取语言信息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 

解决方案

多语言版本资源的存储方式有两种.

最好的方法当然是让一个资源条目包含多个翻译块.这些将可以通过 VerQueryValue 访问.

另一种方法是存储多个资源条目,每种语言一个.这是您存储其他类型的本地化资源(位图、字符串等)的方式.EnumResourceLanguages 应该能够枚举它们,但 GetFileVersionInfo 可能只会选择与您的线程或 UI 语言相匹配的语言.

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

解决方案

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.

这篇关于如何遍历多语言版本资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆