MFC Exntension-DLL Resource-Access question
-
Hi, I'll try to make this as straight forwards as possible :-) I'll describe the situation I want to create and the problem I'm facing as a consequence. I have a simple MFC-App (
MfcApp.exe
). It has a resource-DLL (MfcApp-Res.dll
) which it maps usingAfxSetResourceHandle
. I want to build an MFC-Extension-DLL (MfcExt.dll
) with new controls in it. I want this Extension-DLL to use resources from an additional Dll (MfcExt-Res.dll
). What I would like to have: *MfcExt.dll
loads resources fromMfcExt-Res.dll
*MfcApp.exe
loads resources fromMfcApp-Res.dll
and fromMfcExt-Res.dll
(without explicitly statingMfcExt-Res.dll
anywhere, just by linking toMfcExt.dll
) But, Once the MFC-App will use the MFC-Extension-DLL, I expect a mess, why ? MSDN docs state that the MFC-App and Extension-DLL will use the same resource-dll handle. How can this be handled cleanly ? What is the percise function ofCDynLinkLibrary
in this case ? Thanks for the help, -
Hi, I'll try to make this as straight forwards as possible :-) I'll describe the situation I want to create and the problem I'm facing as a consequence. I have a simple MFC-App (
MfcApp.exe
). It has a resource-DLL (MfcApp-Res.dll
) which it maps usingAfxSetResourceHandle
. I want to build an MFC-Extension-DLL (MfcExt.dll
) with new controls in it. I want this Extension-DLL to use resources from an additional Dll (MfcExt-Res.dll
). What I would like to have: *MfcExt.dll
loads resources fromMfcExt-Res.dll
*MfcApp.exe
loads resources fromMfcApp-Res.dll
and fromMfcExt-Res.dll
(without explicitly statingMfcExt-Res.dll
anywhere, just by linking toMfcExt.dll
) But, Once the MFC-App will use the MFC-Extension-DLL, I expect a mess, why ? MSDN docs state that the MFC-App and Extension-DLL will use the same resource-dll handle. How can this be handled cleanly ? What is the percise function ofCDynLinkLibrary
in this case ? Thanks for the help,The CDynLinkLibrary is a list of libraries loaded dynamically during the run of the MFC program. When the MFC program requires a resource, it will traverse the chain of the dll in the list and stop once it finds the resource that matches. If you want the MfcExt.dll to only use resources from the MfcExt-Res.dll, you have two easy choices as I see it: 1. Always adjust the AfxSetResourceHandle() prior to any calls within MfcExt.dll that might load resources to the MfcExt-Res.dll and then set it BACK once you are done loading resources, which will cause it to load resources from the desired resource dll 2. Only use resouce identifiers in the MfcExt-Res.dll that do not overlap any within the MfcApp-Res.dll module. When the MfcApp.exe tries to load a resource, it will check MfcApp-Res.dll and then search in MfcExt-Res.dll. The MfcExt.dll will do the same search, but it will only find the resources in the MfcApp-Res.dll. I prefer to PLAN my resource utilitization, assign numerical identifier ranges, and go with option 2 myself. It saves tracking down resource loading and a lot of busy work associaed with option 1.