Re: Dynamic linking with symbols
- From: Philip Lawatsch <philip@xxxxxxx>
- Date: Tue, 30 Aug 2005 20:30:02 +0200
Arnaud Debaene schrieb:
Not at all. I've got several singeltons and stuff like that. My plugin simply registers some callbacks inside these singeltons. Thus I need to either pass all the singeltons pointers or pass function pointers to functions hooking the callbacks into the singeltons. Not very elegant imo.
On the contrary, it's very simple and elegant IMHO : just pass the singletons pointers to the plugin when initializing it! By the way, it's the usual, "standard", way of doing this on Windows.
So, I've got the pointer, and what now?
I dont have the .text to do anything with unless I either export it in the exe or also link it into the dll. The latter will result in a bigger dll and also a duplication of code.
Also I'd basically have two singeltons but with the same ptr (since one static ptr to the instance is in my exe and one is in the dll).
Very ugly imo. If you want to for instance lock access to the singleton in a MySingelton::getInstance Method you'd have to write another wrapper or the dll and the exe could both lock it at once (since the static ..data where a lock is stored is twice in the address space).
Since I'm working with OOP quite a lot I definitly would not want a plugin writer to use a c style interface (which you would have to use in your example). Plugins will have to work with objects created in my executable for instance. Writing c wrappers for these would be a pain.
What's wrong with passing the singletons pointers (or references) to the plugin then?
See above, it breaks the design idea, imho.
Btw, DLLs were not designed for OOP, and they work best with a "C" style interface.
Now this for sure is not true. Almost all modern libs (at least the ones I work with) use c++. Although I admin I only know of one other programm importing the .text into the lib and not the other way around.
The usual idiom is to have the plugin export an "Init" C-style function which takes an initialization structure containing all the "callbacks" the plugin may need (in your case, the singletons' pointers) and returns all entry points in the plugin the main app may need. Those entry points can be either an array of functions pointers, either an interface (pointer) that is implemented by the plugin. The interface (base class) is defined by the main app and is implemented in derived classes by the various plugins. The second way is of course much more OOP-ish.
Well, and how is a plugin supposed to work with objects then? Unless your either put all required methods into the dll or export them from the exe there is imo no way to do it.
Imho exporting my core functionality either from the exe or an additional dll is the more elegant solution in my case.
In C, it might be, but not in C++ because of name-mangling : this would render the app and plugins incompatible if they are compiled with different compilers (or different versions of the same compiler). The COM approach to this problem (a v-table like array of function pointers) aims precisely at solving this problem.
I do not care about supporting different compiler versions. Whoever writes a plugin either has to share the source or provide it with the same C++ ABI version as the exe was compiled with. On linux for instance the C++ ABI is quite stable from g++ >=3.4 (iirc). On Windows it's quite stable too. Most users either use VC6 oder 2003.
kind regards Philip .
- Follow-Ups:
- Re: Dynamic linking with symbols
- From: Arnaud Debaene
- Re: Dynamic linking with symbols
- References:
- Dynamic linking with symbols
- From: Philip Lawatsch
- Re: Dynamic linking with symbols
- From: James Brown
- Re: Dynamic linking with symbols
- From: Philip Lawatsch
- Re: Dynamic linking with symbols
- From: Arnaud Debaene
- Dynamic linking with symbols
- Prev by Date: Change Tab Caption Dynamically
- Next by Date: Memory mapped file API failed
- Previous by thread: Re: Dynamic linking with symbols
- Next by thread: Re: Dynamic linking with symbols
- Index(es):
Relevant Pages
|