Re: Adding plugins to my application

From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 05/27/04


Date: Thu, 27 May 2004 09:06:31 +0200


"Tom" <lala@lolo.com> wrote in message
news:c935f1$nul$1@aphrodite.grec.isp.9tel.net...

> Here is what I want : I have a main application that deals with files,
> and I would like it to be able to call some plugins depending on the
> file type (extension). Then regarding the type, the good plugin will
> be loaded, and I would get back some text and a data stream that I
> would use in the main app.
>
> Is there an esay way to do this with dlls ? I didn't manage to find a
> simple yet good tutorial on the web. If someone could explain me a bit
> how it works, or point me out to a good resource...

Perhaps not exactly simple, but elegant - which is to say beautifully
simple when you manage to see through all the regretfully required
details.

The thing to recognise is that the host application defines the plug-in
interface, and all the DLLs offer functionality through the same shape
of keyhole.

I think I wrote a fairly long post about plug-ins here a few months ago;
Google should have it.

Asuuming you can locate and load the right DLL, your problem reduces to
sending it a filename and getting back a string and a stream (TStream?).
This is the basis of your plug-in interface: the DLL should export a
function that transforms these parameters into these output values.

So you just require your DLL to export

function MakeUpABetterNameThan"DoWork"
 (const Filename : String;
  const ReturnData : TStream ): String; stdcall;

I included the stream as an object passed in because returning newly
allocated objects from functions is bad form (now is not the time to
discuss the reasons for this). The DLL can just write to it, and you
can read from it after it returns.

The string return value would not be my first choice; I've learned
to return integer status codes: zero for success, any other value,
preferably negative, for errors. (There's only one way for something
to succeed, but there are usually many ways to fail.) But as long as
you can determine success or failure from it, it doesn't matter all
that much.

It's a good habit to force the calling convention in cross-module
code, and stdcall is the de facto standard.

Groetjes,
Maarten Wiltink



Relevant Pages

  • Re: Dynamic sizing structure?
    ... Each DLL contains a call that creates an object. ... where the plugin provided virtual methods which the client ... when I dynamically loaded the plug-in, ... with the same superclass definition. ...
    (microsoft.public.vc.mfc)
  • Message Map not responding in DLL to WM_SIZE
    ... This is the first time I've written an mfc dll, ... passes them on to a dll protocol plug-in for it to process as it likes. ... I have an object called CNodeConfig. ... m_docked it doesn't resize the CNodeConfig object. ...
    (microsoft.public.vc.mfc)
  • Re: Problem using EngSetPrinterData in user-mode
    ... I have faced such the problem only when I try to set the printer data from ... UNI dll (rendering plug-in). ...
    (microsoft.public.development.device.drivers)
  • Threads & Plug-In DLL
    ... use a plug-in dll with a thread. ... The plug-in is MFC and is derived from ... the thread is MFC and derived from CWinThread. ... in the dll's switch that's used with 'WaitForMultipleObjects', ...
    (microsoft.public.vc.mfc)
  • Re: Manually copying files to emulator in Post Build event
    ... any option to set file type or to set content to true. ... Browse to the location of your dll to include. ... to create a deployment rule, ... They will go to the output directory, also, ...
    (microsoft.public.pocketpc.developer)