在本地DLL中嵌入多个相同命名的资源(RC)文件 [英] Embedding multiple, identically named resource (RC) files in a native DLL

查看:130
本文介绍了在本地DLL中嵌入多个相同命名的资源(RC)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的应用程序(MMC管理单元),我需要创建一个本地DLL,其中包含本地化为不同语言的字符串。换句话说,如果你使用Visual Studio检查这个DLL,你会看到多个字符串表,每个字符串表与不同的区域设置相关联但包含相同的字符串ID。

For my application (an MMC snap-in) I need to create a single native DLL containing strings that are localized into different languages. In other words, if you were to inspect this DLL with Visual Studio, you would see multiple string tables, each associated with a different locale but containing the same string IDs.

我想采取的方法是在我的项目目录下有各种子目录,如de,en,es等(即每种语言一个)。在每个子目录中将是一个名为Resources.rc的文件,它将是包含该语言的字符串的RC文件。将我的资源用于本地化团队是非常理想的。

The approach I would like to take is to have various subdirectories under my project directory such as "de", "en", "es", etc (i.e. one for each language). Inside each subdirectory would be a file called "Resources.rc" which would be the RC file containing the strings for that language. Having my resources in this structure would be ideal for the localisation team.

我已经设法创建了我的各种RC文件,并将它们添加到我的Visual C ++项目。它们都在Visual Studio中的解决方案资源管理器中正确显示(您基本上看到一个名为Resource.rc的条目的五个实例,但每个条目指向不同的文件)。

I have managed to create my various RC files and have added them to my Visual C++ project. They all appear correctly in Solution Explorer in Visual Studio (you basically see five instances of an entry called "Resource.rc", but each entry points to a different file).

问题来自于构建我的项目。似乎只有一个RC文件(在vcproj文件中首先指定的文件)被编译成一个RES文件并包含在我的DLL中。推测这是因为Visual Studio不喜欢这样的事实,RC文件都有相同的名称。

The problem comes with building my project. It seems that only a single one of the RC files (the one that is specified first in the vcproj file) is compiled into a RES file and included into my DLL. Presumably this is because Visual Studio does not like the fact that the RC files all have the same name.

有什么办法来实现我想要的吗?

Is there any way to achieve what I want?

感谢!

推荐答案

是的。和No.
如果你想要多个RC文件,你将不得不利用操作系统支持在一个文件中有多个资源。在资源编辑器中,对于每个资源,您可以设置其语言环境,并且资源编辑器将允许您拥有多个具有相同ID的资源,只要它们的语言区域不同即可。

Yes. And No. If you want multiple RC files you are going to have to leverage off the Operating systems support to have multiple resources in one file. In the resource editor, for each resource, you can set its locale AND the resource editor will allow you to have multiple resources with the same ID, as long as their locale is different.

因此,您的第一步是编辑每个RC文件,以确保其中的资源是英语/美国,另一个包含法语等。

So, your first step would be to edit each of the RC files to ensure that the resources in one are English/US, another contains French etc.

下一页,得到主要的RC文件#include其他。

Next, get the main RC file to #include the others.

最后,这是问题,你需要依靠操作系统逻辑来加载正确的资源。如果您乐意让电脑的区域设置确定您使用的是什么UI语言,您已经做了足够的工作。

Lastly, and this is the problem, you need to rely on the Operating systems logic to load the correct resources. If you are happy to let the locale of the PC determine what UI language is used you have done enough.

如果您想提供一个菜单选项,允许用户更改语言:SetThreadLocale 是在当前线程上切换已加载资源的语言环境的简单方法。由于Windows 2000的一些不幸的重载使用的API已经导致MS不赞成它的使用,赞成要求应用程序开发人员总是使用FindResourceEx - 这真的没有帮助你,例如,从字符串表中加载字符串。

If you want to provide a menu option allowing users to change languages: SetThreadLocale used to be an easy way to switch the Locale of loaded resources on the current thread. Since Windows 2000 some unfortunate overloaded usage of the API has caused MS to deprecate its usage in favor of requiring App Developers to always use FindResourceEx - which really doesn't help you if you want, for example, to load a string from a string table.

如果你真的想要一个简单的方法来拥有用户可选的UI语言,那么你需要将每个.rc文件放入一个单独的dll。然后LoadLibrary对相应的语言资源dll。

If you really want an easy way to have a user selectable UI language, then you need to place each of your .rc files into a seperate dll. and then LoadLibrary on the appropriate language resource dll.

这篇关于在本地DLL中嵌入多个相同命名的资源(RC)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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