Re: LoadLibrary call hangs ..sometime



Although ctor' does not do much but its Init() calls the third party dll
funcions which I believe make some checks with system called Rimage (CD
burner machine)..but the part of calling this ctor' (allocating memory
etc.)
is in extern "C" Init() function for which i need to load my dll into the
memory..

If I understand correctly, the ctor of your static object in your dll calls
an Init function that resides in another dll.
If this is the case, your design is violating the rules that apply to
DllMain, which also apply to static constructors and destructors.

There is no guaranteed load order for Dlls in a process, and depending on
the order in which the Dlls are loaded, you could see
a) no problems at all
b) a deadlock
c) a crash

There is little you can do about it. You might be able to change things
enough that your problem could go away, but you really should not work with
static objects like that. complex static initialization is evil and can
cause a lot of problems.

If you cannot force the application to explicitly do something to initialize
the objects, you can have each function in your DLL check upon entry whether
the object is initialized or not, and then initialize it if it isn't. Guard
the initalization with a critical section to prevent race conditions and you
should be fine.

--
Kind regards,
Bruno van Dooren MVP - VC++
http://msmvps.com/blogs/vanDooren
bruno_nos_pam_van_dooren@xxxxxxxxxxx


.



Relevant Pages

  • Re: LoadLibrary call hangs ..sometime
    ... __declspecint init; ... 1)Once my dll is loaded using loadlibrary i found out the addresses of init ... the ctor of your static object in your dll calls ... If you cannot force the application to explicitly do something to initialize ...
    (microsoft.public.vc.language)
  • Re: MAPIInitialize(NULL) used to fail after 10-15 successfully attempts!!!
    ... Application is a java code which loads this DLL from ... (initialize and uninitialize each time) ... What was the error when you left MAPI initialized? ... Why not call MAPIInitialize once when your app starts and leave MAPI ...
    (microsoft.public.win32.programmer.messaging)
  • Re: MAPIInitialize(NULL) used to fail after 10-15 successfully attempts!!!
    ... I dont know how to degug a dll using VC++. ... and MAPI Developer Tool ... (initialize and uninitialize each time) ... Why not call MAPIInitialize once when your app starts and leave MAPI ...
    (microsoft.public.win32.programmer.messaging)
  • Re: Need some advice
    ... My dll has a class that must be initialized before any ... In the DEMO config, the static Initialize() ... I'm currently writing a remote deployment tool. ...
    (microsoft.public.dotnet.framework)
  • TerminateExtenstion called twice in failed Initialization of ISAPI
    ... Initialization of the DLL fails in GetExtensionVersion. ... The chain of events that leads to the issue is when the call to initialize ... TerminateExtension is called within that failure case and the return value is ...
    (microsoft.public.vc.atl)