无法读取代码页不匹配的FileVersionInfo [英] Can't read FileVersionInfo with Code Page mismatch

查看:200
本文介绍了无法读取代码页不匹配的FileVersionInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些经过合理尝试和测试的代码,这些代码使用Windows API调用读取FileVersionInfo字符串,例如"FileVersion"和"CompanyName".

I have some reasonably tried and tested code which uses the Windows API calls to read FileVersionInfo strings, like "FileVersion" and "CompanyName".

我发现一个特定的第三方DLL失败.问题似乎是这样的:

I found it failed with one particular 3rd party DLL. The problem seems to be this:

读取\VarFileInfo\Translation值,我得到040904B0(美国英语,Unicode).但是,当我随后尝试在\StringFileInfo\040904B0\CompanyName上调用VerQueryValue时,它返回false.

Reading the \VarFileInfo\Translation value, I get 040904B0 (US English, Unicode). But when I then attempt to call VerQueryValue on \StringFileInfo\040904B0\CompanyName, it returns false.

但是调整代码以使用Windows Latin-1 ANSI代码页是可行的:\StringFileInfo\040904E4\CompanyName.

But tweaking the code to use the Windows Latin-1 ANSI codepage works: \StringFileInfo\040904E4\CompanyName.

因此,字符串表中的代码页与\VarFileInfo\Translation值不匹配.

So, the code page in the string table doesn't match the \VarFileInfo\Translation value.

根据MSDN VERSIONINFO资源底部的示例资源文档,这是适当的做法!

According to the example resource at the bottom of MSDN's VERSIONINFO resource documentation, this is an appropriate thing to do!

鉴于此,我可以使用已发布的VersionInfo API正确读取该文件的字符串,而无需猜测"代码页吗?

Given this, can I use the published VersionInfo APIs to correctly read the strings for this file, without "guessing" the codepage?

推荐答案

不幸的是,当从资源文件编译时,VERSIONINFO结构允许您定义字符串块中不存在的语言,以及在语言表中没有任何条目.换句话说,该结构未经过健全性检查.正如 Jonathan Potter 在评论中提到的那样,在使用任意库时,最好的选择是使用启发式搜索来搜索最适合您的应用程序的字符串块.

Unfortunately the VERSIONINFO structure, when compiled from a resource file, allows you to define languages that don't exist in the string block, and string blocks that have no entry in the language table. In other words, the structure isn't sanity checked. As Jonathan Potter mentions in comments, your best bet when working with an arbitrary library is to use a heuristic search for the string block that best fits your application.

但是,在您的情况下,您正在使用VLC库,这些库当前按如下方式定义其版本信息:(已修剪,因此不会占用半页)

In your case, however, you're using the VLC libraries which currently define their version information as follows: (trimmed so it doesn't take half a page)

BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904E4"
    BEGIN
      (...)
    END
  END
  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x409, 1200
  END
END

如您所见,翻译块中的语言是en-us CP1200(UTF-16LE),但是字符串块被标记为en-us CP1252(ANSI Latin 1).奇怪的是,有关主要可执行文件的信息是正确的,并且这些信息几乎是相同的.

As you can see the language in the translation block is en-us CP1200 (UTF-16LE), but the string block is tagged en-us CP1252 (ANSI Latin 1). Oddly enough the information for the main executable is correct, and the information is nearly identical.

雷米·勒博提交了

Remy Lebeau submitted a bug report for the issue, and I've submitted a patch.

自2016年6月24日起,补丁已被接受,并且

As of 24-Jun-2016 the patch has been accepted and backported to the 2.2 maintenance branch.

这篇关于无法读取代码页不匹配的FileVersionInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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