15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


resources in extension DLL

Paul.B.Folbrecht@JCI.Com
Monday, November 18, 1996

     Environment: VC++ 4.1, Windows95
     
     I've been having quite a problem using some resources in an extension 
     DLL I have.  I've read the documentation that states that when MFC 
     tries to load a resource from a DLL, it first searches the .exe (or 
     whatever is returned by AfxGetResourceHandle()), then each DLL in the 
     chain.  As noted, this has the disadvantage of disallowing any 
     duplicate resource IDs accross all DLLs and the exe.  However, I have 
     done this, and am still having problems loading some resources.  
     Specifically, I have a dialog located in an extension DLL whose ID is 
     #defined as 10035, which will not load.  I don't use 
     AfxSetResourceHandle() or anything similar anywhere- this should not 
     be necessary.  I've noticed that certain ranges of constants just 
     don't seem to work while others do.  Is this ID conflicting with 
     something defined by MFC or Windows?
     
     -Paul Folbrecht,
     Compuware Corp.



Herb Stahl -- HStahl@symantec.com
Wednesday, November 20, 1996

I think this should solve your problem.

I have my handy resource switch class which does what you want to do.
I am under the belief that when I make an extension dll that my resource ID's
should not have to conform to a certain range.  Also, if the dll's resource ID's
conflict with the Apps ID's, it sould not matter.  I know what ID's I want to
deal with, and I expect that I should get them first out of my DLL's resource.

1) Notice the 
extern  AFX_EXTENSION_MODULE EXTENSIONDLL; 
The name "EXTENSIONDLL" must match the name which is located in your
"MyExtension.cpp" class, hence the "extern".

Now that that has be done, simply include this header in any module which you
want to load resources from.

Here is an example...........
#include "DllResourceSwitch.h"
void CSomeClass::GetAResourceString()
{

        CDLLResourceState resourceSwitch; // switch the resource handle to this
DLL 
        // OK now I can get my string.
        CString csTemp;
        csTemp.LoadString(IDS_SOME_STRING); // IDS_SOME_STRING can conflict with
your app, but the DLL's string will be loaded.
        
        // upon exit the resourceSwitch destructs and switches the resource
handle back to the original.
}

/////////////////////////////////////////////////////////////////
//DllResourceSwitch.h
extern  AFX_EXTENSION_MODULE EXTENSIONDLL; 
class CDLLResourceState
{
public:
        CDLLResourceState()
                {m_hinstOld = AfxGetResourceHandle();SetToDll();};
        ~CDLLResourceState()
                {SetBack();};
        void SetBack()
                {AfxSetResourceHandle(m_hinstOld);};
        void SetToDll()
                {AfxSetResourceHandle(EXTENSIONDLL.hResource);};
private:
        HINSTANCE m_hinstOld;
};
//////////// End /////////////////////


George H. Stahl
Symantec Corp.

----------
From:   Paul.B.Folbrecht@JCI.Com
Sent:   Monday, November 18, 1996 6:09 PM
To:     mfc-l@netcom.com
Subject:        resources in extension DLL

     Environment: VC++ 4.1, Windows95
     
     I've been having quite a problem using some resources in an extension 
     DLL I have.  I've read the documentation that states that when MFC 
     tries to load a resource from a DLL, it first searches the .exe (or 
     whatever is returned by AfxGetResourceHandle()), then each DLL in the 
     chain.  As noted, this has the disadvantage of disallowing any 
     duplicate resource IDs accross all DLLs and the exe.  However, I have 
     done this, and am still having problems loading some resources.  
     Specifically, I have a dialog located in an extension DLL whose ID is 
     #defined as 10035, which will not load.  I don't use 
     AfxSetResourceHandle() or anything similar anywhere- this should not 
     be necessary.  I've noticed that certain ranges of constants just 
     don't seem to work while others do.  Is this ID conflicting with 
     something defined by MFC or Windows?
     
     -Paul Folbrecht,
     Compuware Corp.
<>




| Вернуться в корень Архива |