Hi,
when loading a library using "LoadLibrary", which itself uses ZConnection an such things, I have a problem with connections in the main programm (AV). My Debuger (event protocol) tells me, that - when starting the main programm - the libpq.dll is loaded (I'm using Delphi 7 and PostgreSQL); when my own DLL is loaded everything is ok, but when I call "FreeLibrary" the libpq.dll is also unloaded ! - and of course - the main programm crashes (I think the TPlainLoader has still all the proc-adresses).
Any ideas ?
Greetings Andreas
Dynamic library loading
Moderators: gto, cipto_kh, EgonHugeist
Hi again - we've got him !
I found a reason for this behavior : it's "GetModuleHandle" in ZPlainLoader; this call *doesn't* increment the referencecounter for the modul (libpd.dll) so the next call to FreeLibrary unloads it (the counter is still 1 from the main programm). I don't know, why this call is made, without it the (normal) LoadLibrary is called (which increments the referencecounter) - and everything works fine !
Greetings Andreas :-)
I found a reason for this behavior : it's "GetModuleHandle" in ZPlainLoader; this call *doesn't* increment the referencecounter for the modul (libpd.dll) so the next call to FreeLibrary unloads it (the counter is still 1 from the main programm). I don't know, why this call is made, without it the (normal) LoadLibrary is called (which increments the referencecounter) - and everything works fine !
Greetings Andreas :-)
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
Hi,
I'm not a specialist in loading DLLs, but as I see it this "GetModuleHandle" is use to avoid that a database DLL is loaded twice, eg when one uses a connection with protocol mysql5 and another with protocol mysql the same dll will be used. Is it possible to load the same DLL twice from the same program using LoadLibrary? Would that cause the library to be loaded twice in memory or would it be reused?
The more : is this behaviour identical if FPC on Windows and FPC on Linux?
Who can give some more insights on this?
Mark
I'm not a specialist in loading DLLs, but as I see it this "GetModuleHandle" is use to avoid that a database DLL is loaded twice, eg when one uses a connection with protocol mysql5 and another with protocol mysql the same dll will be used. Is it possible to load the same DLL twice from the same program using LoadLibrary? Would that cause the library to be loaded twice in memory or would it be reused?
The more : is this behaviour identical if FPC on Windows and FPC on Linux?
Who can give some more insights on this?
Mark
Hi,
IMHO a DLL is only loaded once (as the SDK-Help to LoadLibrary says); I've found a ifdef-ed Funktion "GetModuleHandle" in ZCompatibility which returns always 0 (zero), so I think on non-windows-systems *always* the LoadLibrary (or dlopen because this function is alsoifdef-ed in ZCompatibility) is called. BTW : the IFDEF is FPC.
Andreas
IMHO a DLL is only loaded once (as the SDK-Help to LoadLibrary says); I've found a ifdef-ed Funktion "GetModuleHandle" in ZCompatibility which returns always 0 (zero), so I think on non-windows-systems *always* the LoadLibrary (or dlopen because this function is alsoifdef-ed in ZCompatibility) is called. BTW : the IFDEF is FPC.
Andreas
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
Hi this should be commented out now in SVN testing branch. I'm packaging... takes some time.You can see it soon on http://users.telenet.be/mdaems
Mark
Mark