如何使用MFC重新排列资源ID? [英] How to rearrange resources' ids with MFC ?

查看:178
本文介绍了如何使用MFC重新排列资源ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在使用 MFC扩展DLL 。我需要确保这两个项目的资源ID都不同。

如果我不这样做,我的主应用程序和我的DLL可能会使用相同的ID,在使用资源时会产生问题。例如,我试图从我的DLL显示一个对话框,但是这个对话框的ID与我主应用程序中的其他对话框相同,所以它是显示的主应用程序对话框...



我不仅可以使用#define _APS_NEXT _ * _ VALUE,因为我想让其他人为我的应用程序编写MFC扩展DLL ,他们不会知道我的应用程序和其他扩展程序的资源'ID'范围。



谢谢!



什么我试过了:



研究(论坛,MSDN,..)

Hello,

I am creating a MFC app with a MFC extension DLL, on VC++2017. I need to make sure the resources' IDs are different for both of these projects.
If I don't do it, my main application and my DLL may use the same ID, creating problems when using resources. For example, I am trying to show a dialog from my DLL, but this dialog has the same ID than an other dialog in my main app, so it's the main app dialog which is shown...

I can't only use #define _APS_NEXT_*_VALUE, because I would like to let other people write MFC Extension DLL for my app, and they won't know the resources' ids' ranges of my app and other extensions.

Thanks!

What I have tried:

Researches (forums, MSDN, ..)

推荐答案

请参阅 TN035:使用Visual C ++使用多个资源文件和头文件 [ ^ ]。



对于您的情况,您必须编辑其中一个 resource.h 文件,调整底部的 _APS_NEXT _ * 值资源,并调整所有现有定义,使其在NEXT定义之前,但在到目前为止使用的定义之后加上另一个文件中的新定义空间。请参阅管理多个Visual C ++共享的符号 - 编辑的.RC文件部分中的允许范围的上述链接。



请注意,VS会要求您重新加载在项目打开时编辑文件时的文件。当没有打开相应的项目时接受或更好地编辑文件。





当必须支持多个扩展DLL时应该指定DLL必须使用 HMODULE 加载资源 LoadResource() HINSTANCE 与其他Load函数一起使用。



如果DLL使用MFC,它们必须使用 AfxGetResourceHandle()获取并存储当前资源句柄,通过它们对 AfxSetResourceHandle()的句柄,并在加载资源后恢复设置。另请参见扩展DLL [ ^ ]。

[/ EDIT]
See TN035: Using Multiple Resource Files and Header Files with Visual C++[^].

For your case you have to edit one of the resource.h files, adjust the _APS_NEXT_* values on the bottom for new resources, and adjust all existing definitions to be before the NEXT definitions but after the definitions used so far plus space for new ones in the other file. See the above link for the allowed ranges in the section "Managing Symbols Shared by Multiple Visual C++-Edited .RC Files".

Note that VS will ask you to reload the file when editing it while the project is opened. Accept that or better edit the file when the corrresponding project is not opened.


When multiple extension DLLs must be supported you should specify that the DLLs have to load resources using their HMODULE with LoadResource() and HINSTANCE with the other Load functions.

If the DLLs use MFC, they must get and store the current resource handle using AfxGetResourceHandle(), pass their handle to AfxSetResourceHandle(), and restore the setting after the resource has been loaded. See also Extension DLLs[^].
[/EDIT]


这篇关于如何使用MFC重新排列资源ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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