home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / mswindo / programm / misc / 4424 < prev    next >
Encoding:
Text File  |  1992-12-22  |  1.6 KB  |  53 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!ames!agate!linus!progress!neil
  3. From: neil@progress.COM (Neil Galarneau)
  4. Subject: Re: Force DLL to unload
  5. Message-ID: <1992Dec22.181551.18576@progress.com>
  6. Sender: usenet@progress.com (Mr. Usenet)
  7. Nntp-Posting-Host: pinta
  8. Organization: Progress Software Corp.
  9. References: <DEREKL.92Dec18100741@watson.harlqn.co.uk> <1992Dec18.144024.14800@twisto.eng.hou.compaq.com> <flc.724728723@poseidon>
  10. Date: Tue, 22 Dec 1992 18:15:51 GMT
  11. Lines: 40
  12.  
  13. flc@mips.com (Fred Cox) writes:
  14.  
  15. >mccreary@sword.eng.hou.compaq.com (Ed McCreary) writes:
  16.  
  17. >>In article <DEREKL.92Dec18100741@watson.harlqn.co.uk> derekl@harlqn.co.uk (Derek Law) writes:
  18. >>>Does anybody know how to FORCE Windows 3.1 to unload a DLL? I'm
  19. >>>developing a DLL, but every time I change it I have to quit and
  20. >>>restart Windows - otherwise Windows complains that the file is "still
  21. >>>in use" and so write protected.
  22. >>>
  23.  
  24. >>How are you loading it?  Try this...
  25.  
  26. >>hLib = LoadLibrary("MY.DLL");
  27. >>....program code....
  28. >>FreeLibrary(hLib);
  29.  
  30. >That works for when your DLL works, but when you get a UAE, the thing
  31. >doesn't get FreeLibraried, and you're hosed.
  32.  
  33. [lines deleted...]
  34.  
  35. >Fred Cox
  36. >flc@mti.sgi.com
  37.  
  38. Windows keeps a use count on dlls.  The use count gets incremented on
  39. LoadLibrary and decremented on FreeLibrary.  When the use count drops to zero
  40. the dll is unloaded.
  41.  
  42. If your app UAEs, it never does the FreeLibrary, and any new dll you try to
  43. make is ignored.
  44.  
  45. The solution is to write a trivial program that does:
  46.  
  47. while(GetModuleUsage(hLib))
  48.     FreeLibrary(hLib);
  49.  
  50.  
  51. Neil
  52. neil@progress.com
  53.