7 Replies - 812 Views - Last Post: 22 January 2013 - 02:49 AM Rate Topic: -----

#1 andwan0  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-March 09

HELP: how to load satellite DLL for a DLL

Posted 18 January 2013 - 10:22 AM

I have a Visual C++ workspace that has 2 projects (1 exe & 1 DLL).

I used Serge Wautier's tutorial ( http://www.codeproje...-Selection-Menu ) to create (multi-language) resource DLLs (satellite DLLs) branching off the exe.

Now I have a collection of strings in the DLL that are shared in other projects. I created a satellite DLL for that DLL but can't figure out how to load it on-demand just like the exe's satellite DLL.

He used:
HINSTANCE hDll = LoadLibrary(szFilename);
AfxSetResourceHandle(hDll);
 
void CLanguageSupport::UnloadResourceDll()
{
if (m_hDll!=NULL)
{
SetResourceHandle(AfxGetApp()->m_hInstance); // Restores the EXE as the resource container.
FreeLibrary(m_hDll);
m_hDll= NULL;
}
}


etc etc for the unloading/loading satellite DLLs for the exe.
but how to do the same for the DLL?

This post has been edited by jimblumberg: 18 January 2013 - 10:46 AM
Reason for edit:: Added missing code tags. Please learn to use them properly.


Is This A Good Question/Topic? 0
  • +

Replies To: HELP: how to load satellite DLL for a DLL

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4138
  • View blog
  • Posts: 12,875
  • Joined: 25-December 09

Re: HELP: how to load satellite DLL for a DLL

Posted 18 January 2013 - 10:33 AM

Also posted here. I suggest you stick to using one forum. Posting all over the internet will usually not result in better answers or getting a soultion sooner. Usually the reverse will happen.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1368
  • View blog
  • Posts: 4,737
  • Joined: 19-February 09

Re: HELP: how to load satellite DLL for a DLL

Posted 19 January 2013 - 12:12 PM

Are the strings are in separate DLLs from the language DLLs? Could you add the strings to the language DLLs.


DLL Tutorial For Beginners
Was This Post Helpful? 0
  • +
  • -

#4 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 810
  • View blog
  • Posts: 2,405
  • Joined: 20-March 10

Re: HELP: how to load satellite DLL for a DLL

Posted 19 January 2013 - 02:58 PM

Are you asking how to load a DLL from a DLL

Am I understanding you correctly ?

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#5 andwan0  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-March 09

Re: HELP: how to load satellite DLL for a DLL

Posted 21 January 2013 - 08:14 AM

View Postsnoopy11, on 19 January 2013 - 02:58 PM, said:

Are you asking how to load a DLL from a DLL

Am I understanding you correctly ?

Snoopy.


Kind of.
Original app consisted off several EXEs with 1 shared DLL. The shared DLL contains common strings/resources shared across the EXEs, while the EXE contains specialized/specific strings/resources for it's own project.
So I followed the tutorial on creating "satellite DLLs" for the EXE to enable multi-language menu facility (it loads a satellite DLL on top of the EXE, etc). This works perfectly fine, all the EXE strings are translated. However, strings residing in shared DLL are still untranslated.
So am wondering whether there's such a thing as creating satellite DLLs for DLLs... just like you can do satellite DLLs for EXEs.
Was This Post Helpful? 0
  • +
  • -

#6 andwan0  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-March 09

Re: HELP: how to load satellite DLL for a DLL

Posted 21 January 2013 - 08:21 AM

View Post#define, on 19 January 2013 - 12:12 PM, said:

Are the strings are in separate DLLs from the language DLLs? Could you add the strings to the language DLLs.


DLL Tutorial For Beginners


The standard EXEs contain English strings (strings that are specific to that EXE).
There's a shared DLL containing common/shared strings/resources among the EXEs.
This is a normal project/workspace.

The multi-language menu tutorial let's me create satellite DLLs (strings only) for the EXEs. Which I can translate into other languages.

Yes, I was thinking I could just append the shared DLL's translated strings to the EXE's satellite DLL, assuming I get around the #define conflicts... and making this a repeated-process...
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 810
  • View blog
  • Posts: 2,405
  • Joined: 20-March 10

Re: HELP: how to load satellite DLL for a DLL

Posted 21 January 2013 - 01:25 PM

Although it is possible to load a dll from a dll its frowned upon,

basically its a bad idea, since your DllMain is running inside another call to LoadLibrary, which holds the loader lock.

However it sounds like what you want is a resource only dll.

Or in your case a whole host of different language resource only dll's

You then explicitly link in the required dll at runtime depending

on the locale of your host application(s).

This will avoid having to load a dll from a dll.

Best Wishes.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#8 andwan0  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 19-March 09

Re: HELP: how to load satellite DLL for a DLL

Posted 22 January 2013 - 02:49 AM

I think I got it working:

From VC2005 there's a function called AddResourceInstance() to chain DLLs. However am still using VC6 so this function doesn't exist.

So I just copied some code from a DLL project. The DLL main file contains these lines:

static AFX_EXTENSION_MODULE NEAR extensionDLL = { NULL, NULL };
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
    AfxInitExtensionModule(extensionDLL, hInstance);
    new CDynLinkLibrary(extensionDLL);
}



This dynamically loads the DLL. If we put some of this code into the EXE project like so:


HINSTANCE hDll2 = LoadLibrary(szFilename2);
AfxInitExtensionModule(extensionDLL,hDll2);
new CDynLinkLibrary(extensionDLL);


After the AfxSetResourceHandle(hDll); //setting satellite DLL overriding EXE resources

Originally, the EXE would be the resource container, but AfxSetResourceHandle(satelliteDLL) will set loaded DLL as default resource container, overriding the EXE like.

We use the above extension DLL to chain (add-on) another resource DLL.

The only issues now is freeing the library/memory..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1