Click here to Skip to main content
15,565,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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.


What I have tried:

Researches (forums, MSDN, ..)
Updated 21-Sep-17 4:31am

1 solution

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[^].
Share this answer
SheepSpeech 21-Sep-17 9:22am    

Thanks for your reply. I assume the resources will simply increment by one each time one is added to the project.

However, my final purpose is to let other people create MFC extension DLL for my app. I would like to find a solution which avoid any conflict (and avoid the need to set a range), because people won't know the range used by the main app and other extensions.
Jochen Arndt 21-Sep-17 9:56am    
That was not mentioned in your initial question.

I will update my answer.
SheepSpeech 21-Sep-17 10:14am    
Thank you, I'm gonna try that and give you a feedback !
SheepSpeech 21-Sep-17 10:54am    
I need a piece of advice:
I just want to test something on my extension's dialog, so I would like to quickly change the _APS_NEXT_*_VALUE. However, when I do that, my dialog doesn't appear anymore + its ID is not changed in resource.h. What am I supposed to do?
And also, _APS_NEXT_*_VALUE is the next value for the current project, it's a lower limit, right?
Jochen Arndt 21-Sep-17 11:09am    
The NEXT values are used for new resources. When one is added, the corresponding NEXT value is increased. Existing definitions must be edited manually.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900