CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 1999
    Location
    Canada
    Posts
    2,076

    LoadLibrary and FreeLibrary in DLL

    I have a small problem with LoadLibrary and FreeLibrary in my DLL. For compatibility reason with all WIN OS versions I'm not linking neccessary libraries, but I load them on very begining in entry-point function and getting procedures addresses. It works fine, but it isn't recommended, based on info in MSDN ( You must not call LoadLibrary it says, because you may create dependency loops in the DLL load order ).
    Problem with LoadLibrary function can be fixed easily, but how to use FreeLibrary at the end. Idea like load libraries in every exported functions and then unload at the end don't looks to be like very best solution. What is the proper way to unload libraries if I can't do that in DLL_PROCESS_DETACH in entry-point. I didn't find any info how to do it.

  2. #2
    Join Date
    Jul 2003
    Posts
    8
    How about having a global object in your library containing exported functions and calling the FreeLibrary in the destructor of this global object. Since the destructors for the global objects are called only at the time of dll being unloaded you can ensure that there are no outstanding function calls.
    But I haven't tried this.

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