Shoutbox

Delphi Plugin Framework - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Forum: Plug-Ins (/forumdisplay.php?fid=28)
+------ Thread: Delphi Plugin Framework (/showthread.php?tid=21584)

Delphi Plugin Framework by PsychoMark on 02-19-2004 at 03:34 PM

(sticky maybe?)

For anyone interested in writing Plus! plugins in Delphi, there has been the Delphi Template kindly provided by Whacko. However, while writing several plugins I noted the same pattern over and over again, and got tired of it. So today I wrote a framework for Delphi plugins, and I'm releasing it as open-source...

So what's so special about it? Well, here goes:

  • Full translation of the latest SDK C++ source, including some corrections over Whacko's version
  • Object Orientated way of writing plugins
  • Several wrapper functions for formatting your output, including smart TColor to Plus! color conversion


And what is missing:

  • Implementation of Unicode functions (due to a lack of experience in that area)



The way it's implemented you must create a class descending from TMPPlugin and call RegisterPlugin in the DLL's entry point (the default begin-end you get when creating a DLL project). Override the Initialize function, register your commands (including tags or notifications) and the framework will take over from there, adding your commands to the Plus! plugins menu, calling your callback functions when a command is found. Need more processing? Override the various Execute methods to tap into the processing since all functions are declared as virtual!

Didn't understand a word I was just saying? Not to worry, I've included a demo project showing a plugin with two commands, one tag and a notification.

The advantage of this framework is you no longer have to copy and paste all the code to keep it C++-compatible, the framework takes care of that. No worrying about exports, pointers, correct calling conventions or returning strings longer than the Plus! buffers can handle... all taken care of :)


Before I start to sound like a Tel-Sell comercial, I'll just attach the demo plugin, Plus! SDK conversion and framework. Hope it helps someone as much as it helps me :)




Any feedback, bugs, fixes or Unicode implementations are of course appreciated, what else did I open-source it for eh? :)
RE: Delphi Plugin Framework by PsychoMark on 02-19-2004 at 05:07 PM

Updated the attachment with a newer version. One change in the code: fixed a bug with the menu leaving out the X and for tags even the (!...) part. The X is also no longer added automatically, so I updated the demo project as well to reflect that. The reason is simple: now you can just specify 'xdemo' as the command or tag, which turned out to be easier for the programmer because it resembles the actual command more...


RE: Delphi Plugin Framework by tiojoca on 02-19-2004 at 06:07 PM


Hadn't had the chance to try it yet but the source code is looking good (y) ;)

[off-topic]like your cow avatar too :)[/off-topic]


RE: Delphi Plugin Framework by PsychoMark on 02-22-2004 at 04:10 PM

I replaced the attachment above with a new version, implemented the following changes:

  • Fixed ColorToPlus for RGB values, Plus! wants 3 digits per value
  • Messenger interface is passed in the Messenger property of the plugin now as IDispatch, so you're responsible for checking it's assigned and supports the IMessenger interface...
  • Added support for filters. Explanation below.


Filters

I've seen several people struggling with the fact that Plus! plugins can't output tags like (!IP). Well, they can, but Plus! won't parse 'em so you just get (!IP) in the message instead of the actual IP address. Although this may change in future versions of Plus!, I added filters to the framework to solve it until then. A filter is basically a function which needs to be registered, and gets called whenever the plugin generates output (tags, commands, notifications). These filters may do whatever they like to the output, in the case of the supplied filters I'm using it to emulate the Plus! tags such as (!IP), (!N) and (!FCx). As far as I know all but three tags are supported: (!CN), (!VER) and (!WAT). WAT can be added quite easily, CN hasn't been added because I noticed Patchou scrambled the contact's email addresses (which is good for preventing abuse of course, but bad for me, now I can't read the custom names :)).

The filters included have been split into various units. The way they're designed all you have to do to include the filter is add it to your project, they will register themselves. This makes it easy to exclude tags you don't need...

Because the Pos() function in Delphi is quite limited and StringReplace() is slow, I've used FastStrings for the filters. When you are not using the filters, it's not required to get FastStrings. If you do, FastStrings is easy to install, just dump the files in a directory and make sure that directory is in your library path (Tools -> Environment Options -> Library).


The demo project has also been updated with a /xtags command to show the use of filters.
RE: Delphi Plugin Framework by quietbritishjim on 05-22-2004 at 01:55 PM

Looks good.  I've written quite a few trillian plugins in Delphi (see homepage) and I might just use this to create a couple for messenger plus :)  Will it be updated when ver 3 comes out?

Out of interest, why have you wrapped TMPPlugin in {$M} tags?  This compiler directive only effects classes with published properties and methods, and this class doesn't have any (and presumably its children won't either).


RE: Delphi Plugin Framework by Whacko on 05-23-2004 at 12:23 PM

Looks nice :)

its been a while since i was here :)

its nice to see someone finally made another template :) i made mine in just a few hours as a proof of concept at the time. just so others could start making plugins too :)


RE: Delphi Plugin Framework by PsychoMark on 05-23-2004 at 07:03 PM

@quietbritishjim: yes, I will update it now Plus! 3 is out. Of course plugins are still compatible, with at least the Configure option added I know of... as for the rest, shouldn't take long to figure out, got Plus! 3 installed and loving it...

And as for the RTTI directives; I have no clue why they're there! Presumably I added those as part of some earlier tests which didn't work out... safe to remove 'em, none of the MPPlugin units use 'em...

@Whacko: yeah, used your template as a reference when I was having trouble with the menu items, good work on that earlier...


RE: Delphi Plugin Framework by PsychoMark on 05-24-2004 at 11:25 AM

And here's the update for Plus! 3, thanks to Patchou keeping it all compatible it was easy...


Changes

  • Added mp300 to TMPPlugin.Version
  • Added support for Configure function
  • Filters no longer required! MP3 parses the output of the plugin (even "/xdemo (!xdemo)" works, great job Patchou!). Still keeping the filters in, might come in handy (like WMPlus using it to parse it's custom tags for example :)), but the included filters are now basically useless :)
  • Demo plugin updated, and includes an InstallPlugin application to make installing the plugin while testing easier...


Enjoy!



Edit: attachment removed, instead I updated the attachment in the first post...