将资源编码从 Windows 1252 更改为带签名的 UNICODE UTF-8

发布于 2025-01-10 10:46:11 字数 3046 浏览 0 评论 0原文

我正在开发一个较旧的项目(使用定义的 UNICODE 进行编译),并在 .rc 中遇到了一个问题。例如,包含由

LTEXT "Copyright ©”,IDC_COPYRIGHT_STATIC,7,154,110,8

资源文件在 DIALOGEX 资源中定义的“©”的静态文本元素(可能是多年前由 MSVC 应用程序向导创建并随着每个版本向前迁移),现在看起来像这样:

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252) //present for over 10 years 
#endif

多年来,© 显示正确但最近出现为“Å©”甚至“½¿”。显然,这是一个编码问题,但我需要在进行更改之前了解如何以及为何进行更改。因此,经过研究,.rc 中的这三个属性在错误和编码中发挥了作用:

  1. .rc 中是否存在“#pragma code_page(…)”
  2. 用于使用编码保存< /strong>….rc 文件
  3. 使用编码保存….rc“带签名”或“不带签名”(意思是 BOM?)

Save with Encoding...

作为一项经验测试,在.rc 并查看对话中的结果文本

#pragma code_page(…)保存使用编码签名 (BOM)Dlg 中的文本
code_page(1252)原始文件n/aÅ©
code_page(1252)Windows 1252n/a©
code_page(1252UTF-BOMÅ
)8 65001无 BOMÅ©
code_page(65001)Windows 1252n/a©
code_page(65001)© code_page(1252) UTF-8 65001UTF-8 65001 BOM©
code_page( 65001)UTF-8 65001无 BOM©
中无 code_page.rc UTF-865001 BOM©
中无 code_page.rc UTF-865001无 BOMÅ©

我可以显式使用编码保存所有编码为 Windows 的 .rc 文件 (1252 )或编码为带有签名的 UNICODE UTF-8(并删除#pragma code_pages)。特定的错误将会消失,但这是最好的解决方案吗?

看来从 Windows 1252 切换到 UNICODE UTF-8 是向前迈出的一步,也是长期发展的正确方法。这有什么问题吗?或者更好的解决方案?

I am working on an older project (compiled with UNICODE defined) and came across a problem within the .rc. For example, a static text element which includes “©” defined in a DIALOGEX resource by

LTEXT "Copyright ©”,IDC_COPYRIGHT_STATIC,7,154,110,8

The resource file, probably created by MSVC application wizard many years ago and migrated forward with each release, now looks like this:

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252) //present for over 10 years 
#endif

For many years the © display correctly but recently appeared as “Å©” or even “½¿”. Obviously, an encoding issue, but I needed to understand how and why before making changes. So, after researching, these three properties in the .rc play a part in the bug and the encoding:

  1. The presence or absence of “#pragma code_page(…)” in the .rc
  2. The encoding used to Save with Encoding… the .rc file
  3. Save with Encoding… .rc “with signature” or “without signature” (meaning BOM?)

Save with Encoding...

As an empirical test, changing these things in the .rc and looking at the result text in dialogue

#pragma code_page(…)Save with EncodingSignature(BOM)Text in Dlg
code_page(1252)Original filen/aũ
code_page(1252)Windows 1252n/a©
code_page(1252)UTF-8 65001BOMÅ©
code_page(1252)UTF-8 65001No BOMÅ©
code_page(65001)Windows 1252n/a©
code_page(65001)UTF-8 65001BOM©
code_page(65001)UTF-8 65001No BOM©
No code_page in .rcUTF-8 65001BOM©
No code_page in .rcUTF-8 65001No BOMÅ©

I can explicitly Save with Encoding all .rc files encoding as Windows (1252) OR encoding as UNICODE UTF-8 with signatures (and delete the #pragma code_pages). The specific bug will go away, but is this the best solution?

It seems switching from Windows 1252 to UNICODE UTF-8 is a step forward and the right way to go long term. Is there any problem with this? Or better solutions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁虫ゝ 2025-01-17 10:46:11

Raymond Chen explains the encoding issues in the resource compiler in a blog post stating that when using UTF-8 as encoding for rc files you should not use a BOM/Signature and include a #pragma code_page(65001).

According to a Developer Community issue there are problems in the resource compiler prior to version v10.0.19505.1001. This fixed version ships with Windows SDK 10.0.20348.0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文