Re: Dynamic linking with symbols

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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


.



Relevant Pages

  • Re: How to program plugin DLLs
    ... >own popup menu depending on the plugin that manages it. ... Generally, you should do the GetProcAddress exactly once, when the DLL is loaded, because ... What I might consider here is a method which fills in a popup menu. ... you should keep pointers to objects instead of indices to arrays because array ...
    (microsoft.public.vc.mfc)
  • Re: Access base window class (FromHandlePermanent)
    ... The way I handle this is to specify a "plugin interface". ... The DLL, to be a valid plugin, must export a number of functions that are called by the ... fact that the hosting app might be statically linked, ...
    (microsoft.public.vc.mfc)
  • Re: Dynamically loading DLLs dynamically that have dependencies...
    ... I'm building an app with a simple plugin architecture (all in the same ... In one particular case this dependency is to a C++ DLL called ... Is this DLL having trouble finding it's dependent DLL that's in the ... Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Dynamic linking with symbols
    ... Thus I need to either pass all the singeltons pointers or pass function pointers to functions hooking the callbacks into the singeltons. ... plugin writer to use a c style interface. ...
    (microsoft.public.vc.language)
  • Re: VB6 DLL Beta-test Failure
    ... >I am writing a plugin for APIViewer, a popular development tool, this ... > plugin is in the form of a Visual Basic 6.0 DLL and is based on source ... The DLL filename does not change between versions. ... Always turn on Binary compatibility i VB. ...
    (comp.lang.basic.visual.misc)