什么是保持资源ID同步的推荐方法? [英] What's the reccomended way to keep resource ID's synchronised?

查看:82
本文介绍了什么是保持资源ID同步的推荐方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio项目(C ++),它使用卫星DLL来处理依赖于语言的资源。当我向主项目添加一个新资源并将其复制到附属DLL项目时,即使有两个单独的resource.h文件,神奇地ID似乎也被分配了相同的数值。考虑到ID会被赋予不同的价值,而且一切都会失败 - 特别是如果我需要重新编号资源的话,我会考虑将来的一段时间出现冷汗。



我是否需要担心,如果是这样,最好的方法是确保它们始终保持不变?



我在这个网站上看过一些有趣的文章,但我仍然没有得到它。



我尝试了什么:



我试过将主项目的resource.h包含在卫星的只读符号指令中resource.h(#include.. \ resource.h)但有时当我重建时,资源编译器会将代码更改为其中包含语法错误的内容(它会从包含的文件中删除训练引号)

I have a Visual Studio project (C++) which uses a satellite DLL for language dependent resources. When I add a new resource to the main project and copy it to the satellite DLL project, magically the IDs seem to get assigned the same numerical value even though there are two separate resource.h files. I have cold sweats thinking of some time in the future when the IDs will be assigned different values and it all falls over - especially if I need to renumber the resources.

Do I need to worry, and if so, what would be the best way to ensure they are always kept the same?

I have read some interesting articles on this site about this but I still don't get it.

What I have tried:

I have tried including the main project's resource.h in the read-only symbol directives of the satellite resource.h (#include "..\resource.h") but sometimes when I rebuild, the resource compiler changes the code to something that has a syntax error in it (it removes the training quote mark from the included file)

推荐答案

唯一的方法是将值只包含在两个地方都包含的一个标题中。我这样做,当我这样做时它对我很有用。



要考虑的一件事是DLL的资源ID真的必须在应用程序的资源中可见文件?我想不出他们这样做的情况。我意识到它可以让一些事情变得更方便,但并非绝对必要。这意味着您应该尝试从应用程序的资源文件中删除库的Resource.h文件。 DLL和应用程序中的资源ID可以相同,并且有一些函数允许您选择用于资源查找的句柄来解决这些问题。



在我的新应用程序中,我特别努力使资源ID尽可能少地显示在模块中。实际上,我的对话框处理代码没有任何头文件。定义的接口不涉及任何资源ID。如果你考虑一下,为什么会这样?只有管​​理对话框的特定代码才需要它们。调用对话框的代码不会。它需要做的只是调用一个函数并传递一些数据和父窗口。对话框处理代码管理应用程序的所有数据。应用程序不需要知道对话框中的每个控件以及它们是什么类型的对象或关于对话框的任何其他内容,如ID。这对应用程序来说无关紧要,因为它不会使用任何ID。
The only way to do it is to have the value in only one header that is included in both places. I do this and it is working well for me when I do this.

One thing to consider is do the DLL's resource IDs really have to be visible in the app's resource file? I can't think of a case where they do. I realize it can make some things much more convenient but it is not absolutely necessary. This means you should try removing the inclusion of the library's Resource.h file from the app's resource file. Resource IDs can be the same in the DLL and the app and there are some functions that allow you to select the handle to use for resource lookups which resolves those issues.

In my newer apps I make a special effort to have the resource IDs visible to as few modules as possible. In fact, my dialog handling code does not have any header files. There is an interface defined that does not involve ANY resource IDs. If you think about it, why should there be? Only the specific code that manages the dialog needs them. The code that invokes the dialog doesn't. All it needs to do is call a function and pass it some data and the parent window. The dialog handling code manages all of the data for the app. The app doesn't need to know about every control in the dialog and what type of objects they are or anything else about the dialog like its ID. That doesn't matter to the app because it doesn't use the ID for anything.


这不是魔术,而是一些内置功能。您会在资源标题中看到一些提供该信息的值。它可以错误 - 我有这样的情况,他们可能真的很难察觉。所以避免玩那个游戏。 ;-)



正如Richards写的那样,最好只使用一个resource.h头。这意味着纪律只能在主标题上工作,而不是将其复制到子项目中。不要努力处理已更改的资源数据。



如果真的需要处理一些边缘情况,那么你可以使用未跟踪的rc2文件。
This isnt magic but some built in functionality. You see some values in the of the resource header which provide that information. It can go wrong - I had such cases and they may really hard to detect. So avoid playing that game. ;-)

As Richards wrote it is best to use only one resource.h header. That implies the discipline to work only on the main header and than copy it to the sub project. Dont ferget to work on the changed resource data.

If really need to work with some edge case than you can you the rc2 file which isnt tracked.


这篇关于什么是保持资源ID同步的推荐方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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