How to write an Pegasus Mail Extension using Delphi 4
What you need:
Unpack the Extension Development Kid and read WpmForms.txt as an introduction. A list and documentation of "functions" provided by Pegasus Mail can be found in WpmForms.h. These two files are the most important ones. The last one is the file that could directly used if the extension would be created in C++.
I'll explain writing an extension in Delphi by showing how to create a senseless extension that shows the directory, where PMail is installed. As said, I use Delphi 4 - for different versions it could be slightly different:
- New|DLL: This creates a dpr - file. Save it as DemoPlugin.dpr.
Instead of program DemoPlugin; there can be found
You can ignore the warning that you have to use the unit Sharemem and therefore BORLNDMM.DLL: I know no reason why the PMail extension should export or import Delphi - like strings. So don't use the unit Sharemem.
- Create a new form (like you are used to form normal Delphi programs)- it will be the main form of your extension. I called the unit UMain.pas and the form FMain (type TFMain). Set BorderStyle to bsNone (because Pegasus Mail provides the wrapping - window).
- We'll create this form in DemoPlugin.dpr but we have to destroy it here. So add the following code at the end of UMain.pas:
FMain := nil;
if Assigned(FMain) then FMain.Free;
- As Wpmforms.txt tells us, we have to export a function called FORMINIT. Pegasus Mail calls it when the user Clicks on the button to call our extension. In this function we have to create the form FMain. Look at the Demoplugin.dpr.
- The methods
are necessary to draw our form correctly (just try to leave them away ;-) ).
- procedure TFMain.WmFmInitFocus(var Message: TMessage);
- constructor TFMain.CreateParented(ParentWindow: HWnd);
- If you add a close button to your form, call PostMessage(ParentWindow, WM_CLOSE, 0, 0); instead of Close;
- Look at procedure TFMain.BtnGetBaseDirClick(Sender: TObject); to see how Pegasus Mail and the extension communicate.
- From now on, you can write code as you are used to ;-)
- Write an fff-file for your extension.
- Create a nice Button. Take an existing button as template.
- Copy the button, fff-file and dll-filde in the PMail - Directory.
If you want to debug your extension with Delphi, open Start|Parameter and fill in
- Host-application: C:\Programme\PMail\winpm-32.exe
- Parameter: /I Philipp /a
Further you have to edit the fff - File in the PMail Directory:
Form DLL = X:\PathToDelphiCreatedDll\Demoplugin.dll
You can download the DemoPlugin Source code.