Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / General Programming / dll problems Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

April 19, 2005, 10:16 PM

I load one dll with loadlibrary and try to load another right after and the second one fails. When i release the first then try to load the secont it is successful. I dont feel like loading and unloading for every function i need in a various dlls. Is there some step im missing? Or does windows have this limitation. I am using dev c++.


April 19, 2005, 10:59 PM

I think you're missing something but I can't tell what - can you say what the error is, or even better, post a little bit of code and how it fails.
Cheers, SJ


April 20, 2005, 12:03 AM

as far as my experience tells me, you can load 2 dlls with loadlibrary without unloading any of them. The only pitfall I had with loadlibrary was the directory in which loadlibrary was looking for the dlls. Try specifying the absolute path to the dlls. I can't think of any other problem that could cause this.

- Sid


April 20, 2005, 02:53 AM

here is the code

class MLBase : public Base
virtual ~MLBase(){};
virtual int Load(char *strFileName) = 0;
virtual int Check(char *ext) = 0;
virtual void Destroy() = 0;

int main()
HMODULE hLibrary = LoadLibrary( "test.dll" );
typedef void (*GETPLUGIN)( Base** );
GETPLUGIN pfnLoad = (GETPLUGIN)GetProcAddress( hLibrary, "GetPlugin" );
Base* pOutput = 0;
pfnLoad( &pOutput );
MLBase *m = (MLBase*)pOutput;

if(m == 0)return 0;

HMODULE hhLibrary = LoadLibrary( "test2.dll" );
if(hhLibrary == 0)return 0;
GETPLUGIN ppfnLoad = (GETPLUGIN)GetProcAddress( hhLibrary, "GetPluginn" );
Base* ppOutput = 0;
ppfnLoad( &ppOutput );
MLBase *mm = (MLBase*)ppOutput;

if(mm == 0)return 0;

MessageBox(NULL,"Completed", "Success", MB_OK);

it will load test but fail to load test2. also if i enable sdl or opengl it does the same thing. (guess since they are dlls) HELP!!!!


April 20, 2005, 04:41 AM

If that is the actual code, is that name "GetPluginn" (2 n's) intentional?

Gerald Knizia (cgk)

April 20, 2005, 08:32 AM

So, what exactly does fail (LoadLibrary or GetProcAdress)? And what does GetLastError() say? Are you aware of the "GetPluginn" in the second case?

It is usually no problem to load multiple modules dynamically. Of course this is supported by the OS. The only occasions I can imagine in which loading one of the libraries should break the load of the other ones (modulo "no memory/resources" left and so on) is if at least one of the DLLs is broken.
For example: Both DLLs specify their desired address space, both spaces overlap and the DLLs cannot be relocated (if, for example both DLLs are renamed EXE files which do export functions, but do not contain a reloc section). Also be aware that loading a library will execute its DLL-Main function (if present) or its entry point function. If these functions do strange things (i.e. you don't use the standard functions for this) the effect you're seeing could be achieved (for example: "if( GetModuleHandle( "test.dll" ) ) return false;" in the DLL entry point of test2.dll will prevent it from beeing loaded after test.dll).


April 20, 2005, 02:57 PM

Thanks for responding everyone this problem was driving me crazy. I changed some code in the dll:

added this

BOOL APIENTRY DllMain (HINSTANCE hInst,DWORD reason , LPVOID reserved)
switch (reason)




/* Returns TRUE on success, FALSE on failure */
return TRUE;

and now I an load two with no problems. One more question, I store model loaders in dlls but from some initial tests it looks like i will have compile vector, vertex, blah blah classes into the dll instead of just including the header. Is this correct or what am i missing?


April 20, 2005, 08:44 PM

"I store model loaders in dlls but from some initial tests it looks like i will have compile vector, vertex, blah blah classes into the dll instead of just including the header. Is this correct or what am i missing?"

yes you need to link the dll against the libraries you are using.


This thread contains 8 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.