
C
HAPTER
1: Overview
Plug-in entry point and messages
12
Plug-in entry point and messages
The Illustrator plug-in manager communicates with your plug-in by loading the plug-in code into memory
if necessary, then calling the entry point given by the code-descriptor property in the PiPL. By convention,
the entry point is called
PluginMain
and is compiled with C linkage:
extern "C" ASAPI ASErr PluginMain(char* caller, char* selector, void* message);
Three arguments are passed to the
PluginMain
function; collectively, they make up a
message
.
The first two parameters represent the
message action
, describing what the plug-in is supposed to do, as
described in the following section. The third parameter is a pointer to a data structure, which varies
depending on the message action. When you determine the message action, you typecast the data in the
message
parameter as needed.
The result of the function is an error code.
Message actions: callers and selectors
Each time your plug-in is called, it receives a message action from Illustrator. The message action notifies
your plug-in that an event happened or tells your plug-in to perform an action.
The message action passed to your plug-in consists of two identifiers:
X
The
caller
identifies the sender of the message (PICA, the host application, or a plug-in) and a general
category of action.
X
The selector specifies the action to take within the category of action. All plug-ins receive at least four
message actions: reload, unload, startup and shutdown. In addition, your plug-in may receive
additional message actions specific to the plug-in type.
For example, Illustrator sends a plug-in a menu a message action based on these two strings, when a
menu item added by the plug-in is clicked:
#define kSPAccessCaller "SP Access"
#define kSPAccessUnloadSelector"Unload"
#define kSPAccessReloadSelector"Reload"
The caller and selector identifiers are C strings. By convention, each caller string has a prefix. This is so new
message actions can be easily defined by other applications and plug-ins, with little chance of conflict. For
example, callers and selectors from Illustrator suites use the prefix “AI”, while those from PICA use the prefix
“SP.”
Illustrator message actions are used to indicate events in which a plug-in has interest. Information on the
callers and selectors supported by the API is given by the Plug-in Callers and Plug-in Selectors pages in
Adobe Illustrator API Reference
.