CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2000
    Location
    Dallas, Texas
    Posts
    62

    Call AfxSetResourceHandle in DLL without affecting main application's resources

    I have an MFC application. It loads a DLL (DLL1). DLL1 in turn loads DLL2. DLL2 is used by DLL1 for resources. The problem is when I load DLL2 in DLL1, and call AfxSetResourceHandle(), this causes the resources in the application itself to be reset aswell.

    How can I load resources into a DLL without affecting the resources of the application that loaded it? Both DLLs are MFC Extention DLLs.

  2. #2
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939
    HINSTANCE hOld = AfxGetResourceHandle();
    AfxSetResourceHandle(dllInstance);

    // get your required resources
    AfxSetResourceHandle(hOld);
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  3. #3
    Join Date
    Dec 2000
    Location
    Dallas, Texas
    Posts
    62

    question

    The resource I need to load is a dialog that needs to be loaded up at the time DLL1 is initially loaded. I think what I'm trying to do is not possible; I guess there is one resource handle shared amoung a process (e.g an MFC App and a chain of DLLs all will use the same resource handle ).

    If I'm wrong, please correct me.

  4. #4
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939
    A typical MFC extension DLL has this present:

    Code:
    static AFX_EXTENSION_MODULE MyDLL = { NULL, NULL };
    
            // Insert this DLL into the resource chain
            // NOTE: If this Extension DLL is being implicitly linked to by
            //  an MFC Regular DLL (such as an ActiveX Control)
            //  instead of an MFC application, then you will want to
            //  remove this line from DllMain and put it in a separate
            //  function exported from this Extension DLL.  The Regular DLL
            //  that uses this Extension DLL should then explicitly call that
            //  function to initialize this Extension DLL.  Otherwise,
            //  the CDynLinkLibrary object will not be attached to the
            //  Regular DLL's resource chain, and serious problems will
            //  result.
            
            new CDynLinkLibrary(MyDLL);
    So you may be able to do it by duplicating this functionality.
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured