Re: Dynamic linking with symbols
- From: "Arnaud Debaene" <adebaene@xxxxxxxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 19:54:32 +0200
Philip Lawatsch wrote:
> James Brown schrieb:
>> Personally I would do this differently. Pass a structure full
>> of function-pointers to the DLL (i.e. a bit like a COM interface) -
>> do this when you first initialize the DLL. The DLL just needs to
>> #include a header file which defines this structure and the
>> function-prototypes. It can then call these functions in a portable
>> manner and it doesn't matter *who* passes this
>> structure - it could be a DLL, an EXE or something else.
>> Much easier to maintain/manage/design IMHO.
>
> 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.
> 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?
Btw, DLLs were not designed for OOP, and they work best with a "C" style
interface.
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.
> 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.
Arnaud
MVP - VC
.
- Follow-Ups:
- Re: Dynamic linking with symbols
- From: Philip Lawatsch
- 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
- Dynamic linking with symbols
- Prev by Date: Re: Dynamic linking with symbols
- Next by Date: Change Tab Caption Dynamically
- Previous by thread: Re: Dynamic linking with symbols
- Next by thread: Re: Dynamic linking with symbols
- Index(es):
Relevant Pages
|