-1

I have a question. I'm writing a plugin (.dll) for an application (.exe). And I want to code auto-update function for my plugin but I catched an issue, it could not apply. Because my plugin has loaded while application is running, in run-time it cannot replace. It just apply until application has exited. So, how can I do it?

This is my code: http://codepad.org/4a22ccMa

Thanks!

Vic P.
  • 11
  • 1
  • 3

1 Answers1

0

(this answers the original question, which has been edited to something completely different)

It depends upon the operating system (which I guess might be Windows, since you speak of DLLs; on Linux you have shared objects (in ELF) with a different semantics). Read Levine's book Linkers and Loaders.

You might read more about Dynamic Software Updates. This is a entire research subject with a lot of scientific literature about it. Read e.g. the paper about Kitsune: Efficient, General-purpose Dynamic Software Updating for C (at least to understand several issues in your question).

On Linux, you could rename(2) the old .so and dlopen(3) the new one (and probably dlclose the older one, but you should do that later, when no active call frame on the call stack points into the old plugin), and my manydl.c example shows that you practically can dlopen a big lot (more than a million in practice) of shared objects.

On Windows (which I don't know) you probably need to dynamically load the new version of the plugin in a different file path. Probably, restarting your program after a plugin update should make things much easier.

(if you can afford that, switching to Linux might be very helpful, because I guess that it is much easier)

Notice that in some languages (and some of their implementations) replacing some code is much easier than in C or C++ on Windows. I guess that in CLR (managed code, e.g. in C#) or in a JVM (e.g. in Java, Scala, Clojure) it should be easier. And in Common Lisp (at least with SBCL) it is quite easy (in particular since Common Lisp is an homoiconic language).

Take care of the continuation, i.e. of the call stack. You'll understand that your question (also related to orthogonal persistence & application checkpointing) is much deeper and more difficult than you have imagined. And upgrading classes and their instances is also very difficult.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • I'm sorry but I want to do it on Windows. On Windows it could not be replaced while it loaded in running process. I known an API here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx This API has a flag MOVEFILE_DELAY_UNTIL_REBOOT, it will replace until system is restarted. But this isn't a good idea. I want to replace it when process restart. :( – Vic P. Sep 14 '15 at 10:58
  • Perhaps you want to do something which might be impossible on Windows. Did you try to load a *different* file path for the DLL? You probably need to ask a much better and more focused question and show some source code in it. Don't forget to tag your question correctly (if it is Windows specific, tag is with `Windows`) – Basile Starynkevitch Sep 14 '15 at 11:01
  • I think it not an impossible thing. I saw some application can. It just can contain in the Plugins folder. So I can not change its path. – Vic P. Sep 14 '15 at 11:08
  • As I told you, I don't know Windows and never used it (but I am coding since 1974). So I cannot help you. You should ask a much more specific question and show some code (in that other question). Tag it with Windows if it is specific to Windows. But you should read the paper about *Kitsune*, it is very readable and brings very interesting issues. – Basile Starynkevitch Sep 14 '15 at 11:09
  • I edited my question. Thanks for your answer and I apologize for asking a question is not clear. – Vic P. Sep 14 '15 at 11:18
  • You should ask another question and show several dozens of source code in it. Even with the edit, your question remains unclear. – Basile Starynkevitch Sep 14 '15 at 11:20