在 Windows .rc 文件/dll 中使用字符串类型资源标识符
我们的代码库中有许多 MFC 扩展 dll,其中许多嵌入了项目 .rc 文件中定义的 Windows 资源(IDS_...、IDD_...、IDB_... 等)。我们使用数字标识符来定义我们的资源,特别注意我们的资源 ID 不会在 dll 之间发生冲突,这需要一些管理来确保我们的开发人员不会使用相同的编号。
我意识到字符串类型资源标识符可能是一种简单的方法,这意味着我们可以为每个不同的 dll 中的每个资源定义唯一的标识符。
我的问题是,这样做是否存在任何技术问题,例如:
- MFC dll/资源链是否仍能正常运行?
- Visual Studio 资源编辑器还能工作吗?
我在 MS 技术说明中没有发现任何内容表明这将是一个问题 - 我只是想知道人们是否有过这方面的经验。
We have a number of MFC extension dlls in our code base, many of which have embedded Windows resources defined in the projects .rc files (IDS_..., IDD_..., IDB_... etc). We use numerical identifiers to define our resources, taking special care that our resource ids don't clash across dlls, which requires some management to ensure our developers don't use the same numberings.
I've realised that string-type resource identifiers might be an easy way to go, meaning that we can define unique identifiers for each resource in each different dll.
My question is, are there any technical problems with doing this, for example:
- Will the MFC dll / resource chain still function correctly?
- Will the Visual Studio resource editor still work?
I haven't found anything in the MS Technical Notes to say this would be a problem - I'd just wondering if people have had experience with this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但请注意,字符串表 (IDS_) 中字符串的 ID 必须是数字(16 位 IIRC)。字符串和其他资源之间的区别是由于字符串不是单独的资源。实际上,字符串表由一组资源组成,每个资源最多包含 16 个具有连续 ID 的字符串。
对话框中的控件 ID 也是如此。但你很可能知道这一点。
在资源编辑器中,您只需在资源名称两边加引号即可在属性网格中指定字符串资源 ID。
关于对话框和资源编辑器:您将遇到一个小问题:每当您为对话框创建一个类时,生成的代码都会包含 enum { IDD = resourceid }。不用说,它不适用于字符串 id。但是您可以轻松地摆脱此 IDD 枚举并将其替换为字符串。
Note however that IDs of strings in the string table (IDS_) MUST be numeric (16 bits IIRC). The difference between a string and another resource is due to strings not being individual resources. Actually, the string table consists in a set of resources, each containing up to 16 strings with consecutive IDs.
Same goes for Control IDs within dialogs. But you most likely know that.
In the resource editor, you can specify a string resource id in the property grid by simply putting quotes around the resource names.
Regarding dialogs and the resource editor: You'll have a minor problem: Whenever you create a class for the dialog, the generated code contains enum { IDD = resourceid }. Needless to say that it won't work for a string id. But you can easily get rid of this IDD enum and replace it by a string.