C++ Example
The following example shows how the GetInfo and Execute functions can be used to create a simple plugin to place the selected text in an italic style. This example was written in C++Builder so some of the details may vary depending on which tool you use to compile it.
//---------------------------------------------------------------------------
#include <vcl\\vcl.h>
#include <string.h>
#pragma hdrstop
//---------------------------------------------------------------------------
// Set the information returned by the GetInfo function
static char * Name = "Italic Plugin";
static char * Description = "Applies the italic formatting effect to the selection";
static int MajorVerNo = 1;
static int MinorVerNo = 0;
//---------------------------------------------------------------------------
USERES("Addin.res");
//---------------------------------------------------------------------------
// All addin dll's should include and export the functions GetInfo and Execute.
// The GetInfo function can simply be copied into each addin.
// The Execute function will be passed both all the text in the current document
// and the text which is selected in Constructor.
// It should return the text either all the text or the selected text should be
// replaced by. You specify which section of text is replaced by setting the value
// of Selected in the RetVal structure. To replace only the selected text, set this
// to true, tp replace all the text set it to false. If you only want to add text
// before or after the selection, include the selected text onto the end of the
// additional text you want to insert. If you return an empty string, it will be
// ignored as Constructor will assume the user clicked on a Cancel button
//---------------------------------------------------------------------------
// Export the minimum functions
extern "C" __declspec(dllexport) void __stdcall GetInfo(char **, char **, int *, int *);
extern "C" __declspec (dllexport) struct RetVal __stdcall Execute(char *, char *);
//---------------------------------------------------------------------------
// Define type used by Execute function
typedef struct RETVAL {char * Text; bool Selected;} RETVAL;
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
return 1;
}
//---------------------------------------------------------------------------
void __stdcall GetInfo(char ** GetName, char ** GetDescription, int * GetMajorVerNo, int * GetMinorVerNo)
{
// Return information set up above
*GetName = Name;
*GetDescription = Description;
*GetMajorVerNo = MajorVerNo;
*GetMinorVerNo = MinorVerNo;
}
//---------------------------------------------------------------------------
RETVAL __stdcall Execute(char * Text, char * Selected)
{
// Example to put italic formatting tags around selected text
// Declare variables to hold string with tags around, and the tags seperately
// The total string only needs to be 32KB long as this is the maximum length
// of a document in Constructor
char String[32 * 1024];
char *Start = "<i>", *End = "</i>";
// Copy first tag into string
strcpy(String, Start);
// Add on the selected text
strcat(String, Selected);
// Add on the closing tag
strcat(String, End);
// Create RetVal structure to return
RETVAL ReturnValue;
// Set text to return
ReturnValue.Text = String;
// Specify that we only want to replace the selected text
ReturnValue.Selected = true;
// Return the structure
return ReturnValue;
}
//---------------------------------------------------------------------------
}