How to Release or Update a DLL - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to Release or Update a DLL

dubidubi Posts: 121Member
My application creates a DLL at runtime and this DLL will
be used by the other Testing Application for a testing process.
When my application creates a DLL of the same name that is handled by the Testing Application,it is not being updated.

So I have to close the Testing Application and then create my DLL and
the open the Testing Application.
How to release or update the DLL which is being Handled or used by the Testing Application from my program.

My question is how to release a DLL(eg.MyDLL.dll) which being handled by the other application before creating the same DLL(MyDLL.dll).

Thanks for your suggestions.

Comments

  • zibadianzibadian Posts: 6,349Member
    : My application creates a DLL at runtime and this DLL will
    : be used by the other Testing Application for a testing process.
    : When my application creates a DLL of the same name that is handled by the Testing Application,it is not being updated.
    :
    : So I have to close the Testing Application and then create my DLL and
    : the open the Testing Application.
    : How to release or update the DLL which is being Handled or used by the Testing Application from my program.
    :
    : My question is how to release a DLL(eg.MyDLL.dll) which being handled by the other application before creating the same DLL(MyDLL.dll).
    :
    : Thanks for your suggestions.
    :
    One of the tricks used in these cases is that the original DLL is renamed, which is allowed by windows even while the DLL is being used. Then you can create the update. To truly install the update you need to free the library and then load it again. For this to work while the test application is running, the library must be dynamically liked to the application instead of static linked.
  • dubidubi Posts: 121Member
    : : My application creates a DLL at runtime and this DLL will
    : : be used by the other Testing Application for a testing process.
    : : When my application creates a DLL of the same name that is handled by the Testing Application,it is not being updated.
    : :
    : : So I have to close the Testing Application and then create my DLL and
    : : the open the Testing Application.
    : : How to release or update the DLL which is being Handled or used by the Testing Application from my program.
    : :
    : : My question is how to release a DLL(eg.MyDLL.dll) which being handled by the other application before creating the same DLL(MyDLL.dll).
    : :
    : : Thanks for your suggestions.
    : :
    : One of the tricks used in these cases is that the original DLL is renamed, which is allowed by windows even while the DLL is being used. Then you can create the update. To truly install the update you need to free the library and then load it again. For this to work while the test application is running, the library must be dynamically liked to the application instead of static linked.
    :


    Renaming the DLL which is currently used by the Test Application will not change the content(the Functions) of the DLL,rather only the name of the DLL changes.
    Actually my program creates a .C file,compile(.obj file) it and then Link with other Library files(Host Library) and then creates a DLL at runtime with a linker ILINK32.exe.I dont create the DLL with a DLL wizard.

    So when my application creates a new DLL of the same name that is being
    used by the Test Application,it cannot be updated or dynamically changed.
    " To truly install the update you need to free the library and then load it again."

    When the Test Application runs,it uses my program DLL and when
    the functions in my DLL is used,the Test Application uses the Host Library files.So this Library files cannot be removed.






  • sziszi81sziszi81 Posts: 80Member
    : Renaming the DLL which is currently used by the Test Application will not change the content(the Functions) of the DLL,rather only the name of the DLL changes.
    : Actually my program creates a .C file,compile(.obj file) it and then Link with other Library files(Host Library) and then creates a DLL at runtime with a linker ILINK32.exe.I dont create the DLL with a DLL wizard.
    :
    : So when my application creates a new DLL of the same name that is being
    : used by the Test Application,it cannot be updated or dynamically changed.
    : " To truly install the update you need to free the library and then load it again."
    :
    : When the Test Application runs,it uses my program DLL and when
    : the functions in my DLL is used,the Test Application uses the Host Library files.So this Library files cannot be removed.
    :
    :

    Why not?

    Main Application has a button which will delete/rename the DLL and generate a new DLL (with new functions etc.) under the same name.

    Test Application has an Update button which will free the DLL and load it again. It just as zibadian said it has to be dynamically linked.

  • zibadianzibadian Posts: 6,349Member
    : : : My application creates a DLL at runtime and this DLL will
    : : : be used by the other Testing Application for a testing process.
    : : : When my application creates a DLL of the same name that is handled by the Testing Application,it is not being updated.
    : : :
    : : : So I have to close the Testing Application and then create my DLL and
    : : : the open the Testing Application.
    : : : How to release or update the DLL which is being Handled or used by the Testing Application from my program.
    : : :
    : : : My question is how to release a DLL(eg.MyDLL.dll) which being handled by the other application before creating the same DLL(MyDLL.dll).
    : : :
    : : : Thanks for your suggestions.
    : : :
    : : One of the tricks used in these cases is that the original DLL is renamed, which is allowed by windows even while the DLL is being used. Then you can create the update. To truly install the update you need to free the library and then load it again. For this to work while the test application is running, the library must be dynamically liked to the application instead of static linked.
    : :
    :
    :
    : Renaming the DLL which is currently used by the Test Application will not change the content(the Functions) of the DLL,rather only the name of the DLL changes.
    : Actually my program creates a .C file,compile(.obj file) it and then Link with other Library files(Host Library) and then creates a DLL at runtime with a linker ILINK32.exe.I dont create the DLL with a DLL wizard.
    :
    : So when my application creates a new DLL of the same name that is being
    : used by the Test Application,it cannot be updated or dynamically changed.
    : " To truly install the update you need to free the library and then load it again."
    :
    : When the Test Application runs,it uses my program DLL and when
    : the functions in my DLL is used,the Test Application uses the Host Library files.So this Library files cannot be removed.
    :
    The steps of changing/updating a library are as follows:
    - Rename the currely linked DLL
    - Compile/build the new DLL and give it the old name
    - Free the currently linked DLL
    - Load the new DLL using the old name
    - Delete the renamed old DLL

    Example:
    Suppose you have a DLL called "plugin1.dll". The update will proceed as follows:
    - rename "plugin1.dll" to "temp.dll"
    - Compile a new "plugin1.dll"
    - Free "temp.dll"
    - Load "plugin1.dll"
    - Delete "temp.dll"

    I hope this clarifies the method a bit.
  • dubidubi Posts: 121Member
    : : Renaming the DLL which is currently used by the Test Application will not change the content(the Functions) of the DLL,rather only the name of the DLL changes.
    : : Actually my program creates a .C file,compile(.obj file) it and then Link with other Library files(Host Library) and then creates a DLL at runtime with a linker ILINK32.exe.I dont create the DLL with a DLL wizard.
    : :
    : : So when my application creates a new DLL of the same name that is being
    : : used by the Test Application,it cannot be updated or dynamically changed.
    : : " To truly install the update you need to free the library and then load it again."
    : :
    : : When the Test Application runs,it uses my program DLL and when
    : : the functions in my DLL is used,the Test Application uses the Host Library files.So this Library files cannot be removed.
    : :
    : :
    :
    : Why not?
    :
    : Main Application has a button which will delete/rename the DLL and generate a new DLL (with new functions etc.) under the same name.
    :
    : Test Application has an Update button which will free the DLL and load it again. It just as zibadian said it has to be dynamically linked.
    :
    :
    Thanks for your suggestions.
    The DLL is renamed well.
    But when I look into the time the DLL created,it is not the
    current time.
    I mean the DLL is just renamed when it was last time created.
    I even deleted the intermediate files such as .obj,.ils,.tds etc.,
    but the time created for the renamed DLL is same always.
    But when I use the Debug mode,then the DLL renamed shows the current
    time of file creation.
    I tried even Sleep(200),because of the time delay.
    Still not the current time is shown for the renamed DLL.
    I don't why while running the program it is not updated but on Debug mode it is ok.



  • dubidubi Posts: 121Member
    : : : : My application creates a DLL at runtime and this DLL will
    : : : : be used by the other Testing Application for a testing process.
    : : : : When my application creates a DLL of the same name that is handled by the Testing Application,it is not being updated.
    : : : :
    : : : : So I have to close the Testing Application and then create my DLL and
    : : : : the open the Testing Application.
    : : : : How to release or update the DLL which is being Handled or used by the Testing Application from my program.
    : : : :
    : : : : My question is how to release a DLL(eg.MyDLL.dll) which being handled by the other application before creating the same DLL(MyDLL.dll).
    : : : :
    : : : : Thanks for your suggestions.
    : : : :
    : : : One of the tricks used in these cases is that the original DLL is renamed, which is allowed by windows even while the DLL is being used. Then you can create the update. To truly install the update you need to free the library and then load it again. For this to work while the test application is running, the library must be dynamically liked to the application instead of static linked.
    : : :
    : :
    : :
    : : Renaming the DLL which is currently used by the Test Application will not change the content(the Functions) of the DLL,rather only the name of the DLL changes.
    : : Actually my program creates a .C file,compile(.obj file) it and then Link with other Library files(Host Library) and then creates a DLL at runtime with a linker ILINK32.exe.I dont create the DLL with a DLL wizard.
    : :
    : : So when my application creates a new DLL of the same name that is being
    : : used by the Test Application,it cannot be updated or dynamically changed.
    : : " To truly install the update you need to free the library and then load it again."
    : :
    : : When the Test Application runs,it uses my program DLL and when
    : : the functions in my DLL is used,the Test Application uses the Host Library files.So this Library files cannot be removed.
    : :
    : The steps of changing/updating a library are as follows:
    : - Rename the currely linked DLL
    : - Compile/build the new DLL and give it the old name
    : - Free the currently linked DLL
    : - Load the new DLL using the old name
    : - Delete the renamed old DLL
    :
    : Example:
    : Suppose you have a DLL called "plugin1.dll". The update will proceed as follows:
    : - rename "plugin1.dll" to "temp.dll"
    : - Compile a new "plugin1.dll"
    : - Free "temp.dll"
    : - Load "plugin1.dll"
    : - Delete "temp.dll"
    :
    : I hope this clarifies the method a bit.
    :
    Thanks for your suggestions.
    The DLL is quite renamed.
    Not just renaming,I followed the procedure as you mentioned.
    Rename old DLL,compile new dll,delete old DLL.
    But the time created for the Renamed DLL is not the current time.
    When I execute the program in Debug mode,i.e tracing the program step by step,the newly created DLL shows the current time it is created.
    I even used Sleep(200) assuming because of the time delay because it
    works in Debug mode.But Sleep also does not work.
    The DLL is renamed,but the time of creation of DLL is same as the old
    DLL,which means it is only renamed and not updated.
    It shows the previously created time even after Renaming the DLL.

  • zibadianzibadian Posts: 6,349Member
    : : : : : My application creates a DLL at runtime and this DLL will
    : : : : : be used by the other Testing Application for a testing process.
    : : : : : When my application creates a DLL of the same name that is handled by the Testing Application,it is not being updated.
    : : : : :
    : : : : : So I have to close the Testing Application and then create my DLL and
    : : : : : the open the Testing Application.
    : : : : : How to release or update the DLL which is being Handled or used by the Testing Application from my program.
    : : : : :
    : : : : : My question is how to release a DLL(eg.MyDLL.dll) which being handled by the other application before creating the same DLL(MyDLL.dll).
    : : : : :
    : : : : : Thanks for your suggestions.
    : : : : :
    : : : : One of the tricks used in these cases is that the original DLL is renamed, which is allowed by windows even while the DLL is being used. Then you can create the update. To truly install the update you need to free the library and then load it again. For this to work while the test application is running, the library must be dynamically liked to the application instead of static linked.
    : : : :
    : : :
    : : :
    : : : Renaming the DLL which is currently used by the Test Application will not change the content(the Functions) of the DLL,rather only the name of the DLL changes.
    : : : Actually my program creates a .C file,compile(.obj file) it and then Link with other Library files(Host Library) and then creates a DLL at runtime with a linker ILINK32.exe.I dont create the DLL with a DLL wizard.
    : : :
    : : : So when my application creates a new DLL of the same name that is being
    : : : used by the Test Application,it cannot be updated or dynamically changed.
    : : : " To truly install the update you need to free the library and then load it again."
    : : :
    : : : When the Test Application runs,it uses my program DLL and when
    : : : the functions in my DLL is used,the Test Application uses the Host Library files.So this Library files cannot be removed.
    : : :
    : : The steps of changing/updating a library are as follows:
    : : - Rename the currely linked DLL
    : : - Compile/build the new DLL and give it the old name
    : : - Free the currently linked DLL
    : : - Load the new DLL using the old name
    : : - Delete the renamed old DLL
    : :
    : : Example:
    : : Suppose you have a DLL called "plugin1.dll". The update will proceed as follows:
    : : - rename "plugin1.dll" to "temp.dll"
    : : - Compile a new "plugin1.dll"
    : : - Free "temp.dll"
    : : - Load "plugin1.dll"
    : : - Delete "temp.dll"
    : :
    : : I hope this clarifies the method a bit.
    : :
    : Thanks for your suggestions.
    : The DLL is quite renamed.
    : Not just renaming,I followed the procedure as you mentioned.
    : Rename old DLL,compile new dll,delete old DLL.
    : But the time created for the Renamed DLL is not the current time.
    : When I execute the program in Debug mode,i.e tracing the program step by step,the newly created DLL shows the current time it is created.
    : I even used Sleep(200) assuming because of the time delay because it
    : works in Debug mode.But Sleep also does not work.
    : The DLL is renamed,but the time of creation of DLL is same as the old
    : DLL,which means it is only renamed and not updated.
    : It shows the previously created time even after Renaming the DLL.
    :
    :
    I have tested the code method I described and it works like a charm. Here is my code:
    [code]
    library testdll;

    function TestGet: integer StdCall;
    begin
    Result := 1; // <= change this value to indicate a new version
    end;

    exports
    TestGet;

    begin
    end.
    [/code]
    In the executable I have these events:
    [code]
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    // Link to test dll
    FTestHandle := LoadLibrary('testdll.dll');
    FTestProc := TTestProc(GetProcAddress(FTestHandle, 'TestGet'));
    end;

    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    // release the test dll
    FreeLibrary(FTestHandle);
    end;

    procedure TForm1.btnRunDLLClick(Sender: TObject);
    begin
    Label1.Caption := IntToStr(FTestProc);
    end;

    procedure TForm1.btnRenameDLLClick(Sender: TObject);
    begin
    // rename the dll
    RenameFile('testdll.dll', 'testdll2.dll');
    // then manually recompile it using Delphi
    // You can perform this action automatically
    end;

    procedure TForm1.btnUpdateDLLClick(Sender: TObject);
    begin
    // Perform actual update
    FreeLibrary(FTestHandle);
    FTestHandle := LoadLibrary('testdll.dll');
    FTestProc := TTestProc(GetProcAddress(FTestHandle, 'TestGet'));
    end;
    [/code]
    If I run the program and first rename the DLL, then change the result of the TestGet(), and press the Update button, the label shows the change perfectly.
    I have also checked the creation time. Those remain the same because in the opinion of windows the file wasn't recreated but only changed. The changed time reflects the new compile time.
  • dubidubi Posts: 121Member
    : : : : : : My application creates a DLL at runtime and this DLL will
    : : : : : : be used by the other Testing Application for a testing process.
    : : : : : : When my application creates a DLL of the same name that is handled by the Testing Application,it is not being updated.
    : : : : : :
    : : : : : : So I have to close the Testing Application and then create my DLL and
    : : : : : : the open the Testing Application.
    : : : : : : How to release or update the DLL which is being Handled or used by the Testing Application from my program.
    : : : : : :
    : : : : : : My question is how to release a DLL(eg.MyDLL.dll) which being handled by the other application before creating the same DLL(MyDLL.dll).
    : : : : : :
    : : : : : : Thanks for your suggestions.
    : : : : : :
    : : : : : One of the tricks used in these cases is that the original DLL is renamed, which is allowed by windows even while the DLL is being used. Then you can create the update. To truly install the update you need to free the library and then load it again. For this to work while the test application is running, the library must be dynamically liked to the application instead of static linked.
    : : : : :
    : : : :
    : : : :
    : : : : Renaming the DLL which is currently used by the Test Application will not change the content(the Functions) of the DLL,rather only the name of the DLL changes.
    : : : : Actually my program creates a .C file,compile(.obj file) it and then Link with other Library files(Host Library) and then creates a DLL at runtime with a linker ILINK32.exe.I dont create the DLL with a DLL wizard.
    : : : :
    : : : : So when my application creates a new DLL of the same name that is being
    : : : : used by the Test Application,it cannot be updated or dynamically changed.
    : : : : " To truly install the update you need to free the library and then load it again."
    : : : :
    : : : : When the Test Application runs,it uses my program DLL and when
    : : : : the functions in my DLL is used,the Test Application uses the Host Library files.So this Library files cannot be removed.
    : : : :
    : : : The steps of changing/updating a library are as follows:
    : : : - Rename the currely linked DLL
    : : : - Compile/build the new DLL and give it the old name
    : : : - Free the currently linked DLL
    : : : - Load the new DLL using the old name
    : : : - Delete the renamed old DLL
    : : :
    : : : Example:
    : : : Suppose you have a DLL called "plugin1.dll". The update will proceed as follows:
    : : : - rename "plugin1.dll" to "temp.dll"
    : : : - Compile a new "plugin1.dll"
    : : : - Free "temp.dll"
    : : : - Load "plugin1.dll"
    : : : - Delete "temp.dll"
    : : :
    : : : I hope this clarifies the method a bit.
    : : :
    : : Thanks for your suggestions.
    : : The DLL is quite renamed.
    : : Not just renaming,I followed the procedure as you mentioned.
    : : Rename old DLL,compile new dll,delete old DLL.
    : : But the time created for the Renamed DLL is not the current time.
    : : When I execute the program in Debug mode,i.e tracing the program step by step,the newly created DLL shows the current time it is created.
    : : I even used Sleep(200) assuming because of the time delay because it
    : : works in Debug mode.But Sleep also does not work.
    : : The DLL is renamed,but the time of creation of DLL is same as the old
    : : DLL,which means it is only renamed and not updated.
    : : It shows the previously created time even after Renaming the DLL.
    : :
    : :
    : I have tested the code method I described and it works like a charm. Here is my code:
    : [code]
    : library testdll;
    :
    : function TestGet: integer StdCall;
    : begin
    : Result := 1; // <= change this value to indicate a new version
    : end;
    :
    : exports
    : TestGet;
    :
    : begin
    : end.
    : [/code]
    : In the executable I have these events:
    : [code]
    : procedure TForm1.FormCreate(Sender: TObject);
    : begin
    : // Link to test dll
    : FTestHandle := LoadLibrary('testdll.dll');
    : FTestProc := TTestProc(GetProcAddress(FTestHandle, 'TestGet'));
    : end;
    :
    : procedure TForm1.FormDestroy(Sender: TObject);
    : begin
    : // release the test dll
    : FreeLibrary(FTestHandle);
    : end;
    :
    : procedure TForm1.btnRunDLLClick(Sender: TObject);
    : begin
    : Label1.Caption := IntToStr(FTestProc);
    : end;
    :
    : procedure TForm1.btnRenameDLLClick(Sender: TObject);
    : begin
    : // rename the dll
    : RenameFile('testdll.dll', 'testdll2.dll');
    : // then manually recompile it using Delphi
    : // You can perform this action automatically
    : end;
    :
    : procedure TForm1.btnUpdateDLLClick(Sender: TObject);
    : begin
    : // Perform actual update
    : FreeLibrary(FTestHandle);
    : FTestHandle := LoadLibrary('testdll.dll');
    : FTestProc := TTestProc(GetProcAddress(FTestHandle, 'TestGet'));
    : end;
    : [/code]
    : If I run the program and first rename the DLL, then change the result of the TestGet(), and press the Update button, the label shows the change perfectly.
    : I have also checked the creation time. Those remain the same because in the opinion of windows the file wasn't recreated but only changed. The changed time reflects the new compile time.
    :
    That's great.It works.
    Thank you friend.

  • MasterijnMasterijn Posts: 188Member
    : : : Renaming the DLL which is currently used by the Test Application will not change the content(the Functions) of the DLL,rather only the name of the DLL changes.
    : : : Actually my program creates a .C file,compile(.obj file) it and then Link with other Library files(Host Library) and then creates a DLL at runtime with a linker ILINK32.exe.I dont create the DLL with a DLL wizard.
    : : :
    : : : So when my application creates a new DLL of the same name that is being
    : : : used by the Test Application,it cannot be updated or dynamically changed.
    : : : " To truly install the update you need to free the library and then load it again."
    : : :
    : : : When the Test Application runs,it uses my program DLL and when
    : : : the functions in my DLL is used,the Test Application uses the Host Library files.So this Library files cannot be removed.
    : : :
    : : :
    : :
    : : Why not?
    : :
    : : Main Application has a button which will delete/rename the DLL and generate a new DLL (with new functions etc.) under the same name.
    : :
    : : Test Application has an Update button which will free the DLL and load it again. It just as zibadian said it has to be dynamically linked.
    : :
    : :
    : Thanks for your suggestions.
    : The DLL is renamed well.
    : But when I look into the time the DLL created,it is not the
    : current time.
    : I mean the DLL is just renamed when it was last time created.
    : I even deleted the intermediate files such as .obj,.ils,.tds etc.,
    : but the time created for the renamed DLL is same always.
    : But when I use the Debug mode,then the DLL renamed shows the current
    : time of file creation.
    : I tried even Sleep(200),because of the time delay.
    : Still not the current time is shown for the renamed DLL.
    : I don't why while running the program it is not updated but on Debug mode it is ok.
    :
    The renamed dll is still loaded (even when no application is using it at the moment) under it's orginal name.
    There's a systemwide registery setting, which tells windows to unload dll's directly. If you set this option, than the dll can be deleted/replaced (when all applications have uloaded).


Sign In or Register to comment.