Announcement

Collapse
No announcement yet.

Unload/free up a DLL from an external process?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unload/free up a DLL from an external process?

    I'm not sure if this is possible, it certainly seems kind of kinky to me and may even need SeDebugPrivilege or attaching a thread to a process, but if it is it would be extremely handy... one of my programs uses a DLL. Every month the DLL gets updated. I would like my update program to be able to free the DLL from this other process -- and I can't modify the source of the original to do it, which is why I need to do it externally from a different process
    eg. Program.exe loads wayne.dll ... I'd like to send people update.exe, which finds Program.exe in the process list, and then frees up wayne.dll so that it can replace it
    Anyone?


    ------------------
    -

  • #2
    If program.exe loads the DLL with LoadLibrary you can do this.

    But if wayne.dll is loaded implicitly (i.e., is in the import table), you cannot unload it while program.exe is running.

    I started writing on-line a method to do this, but even if you use LoadLibrary, the mechanics are turning out to be a bit tricky.

    Let me spend some time on this. But it will all depend on you using LoadLibrary rather than implied DLL loading.

    Just as another thought, if all you are changing in wayne.dll is a resource, The UpdateResource API call might be an option.

    MCM


    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      From WIN32.HLP:
      Calling FreeLibrary does not affect other processes using the same library module.
      I'd suggest that app uses run-time linking (explicitly use LoadLibrary, etc). However, before loading the DLL, the app should make a copy of the original DLL file and use LoadLibrary on the copy instead.

      This means that the original DLL is not locked, and can be over-written without any problems.

      When you want to update the DLL, simply copy the new DLL over the original file. You could also signal the running app to close itself down. Next time the app is launched, the updated DLL will be used automatically.




      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Lance, that's an excellent method thanks, I'll be using that, but I can't with this, as I can't modify the source to the program that actually loads the DLL - thats the catch. Dont ask why, I just cant modify Program.exe in this one particular case. Program.exe loads wayne.dll ... I need my update.exe (which is the only program other than wayne.dll that I can modify) to somehow free the library from program.exe... again Im not sure if that is possible, but it would be very very cool to be able to do this
        Michael, ive never heard of UpdateResource before, ill scoop through MSDN for some docs on it, thanks. Incidently, "program.exe" is a VB program, with Declare Function Blah Lib "wayne.dll" in it - Im not sure if VB exes load with an import table or through LoadLibary, or...
        Thanks,
        Wayne


        ------------------
        -

        Comment


        • #5
          Wayne,
          I am doing that on our network by simply renaming the DLL that is in use. While this seems to work when the DLL and the executable are both running on an NT server, I can not use it on my local machine.

          Regards,


          Peter Redei

          ------------------

          Comment


          • #6
            Incidently, "program.exe" is a VB program, with Declare Function Blah Lib "wayne.dll" in it - Im not sure if VB exes load with an import table or through LoadLibary, or...
            I found a piece of $20.00 shareware(*)called "PEBrowse" which shows you the import, export and resource tables. you load an EXE or DLL, and you get the list of DLLs needed and the procnames used. You can get it a number of places, and I'm sure there are some others.

            But I think (and I know PB works this way) if a procedure is DECLAREd with a "LIB" in it and is used, that DLL will be in the import table and is loaded when the program starts, and must be present to allow the program to even start up.

            See the PB CALL DWORD in the help file; it shows that when you declare the function prototype you do NOT use a "LIB" clause, so the DLL will not have to be present to run.

            (I am using this "loadlibrary" method on my current project. There are three separate DLLs you can use with the product; you only get those you license. But all the rest of the code is common, so it will load and run even if you have no "component" DLLs.) (It don't do much then, but it DOES run and tells you no options are installed).

            MCM
            * If you get a Streamwood IL address for Prudens, Inc. in the ZIP file, it's bad (my check was returned). The correct address is in Schaumburg IL.

            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment

            Working...
            X