文章目录

  • 1.入口点函数
  • 2.作者答疑

1.入口点函数

  插件作为illustrator软件的一部分,需要与主体程序进行通信,必然需要约定调用函数。而入口点函数就是其中关键一环,实例代码如下:

/** Basic suite-access information provided with every call. */
struct SPMessageData {#ifdef __cplusplusSPMessageData(ai::int32 SPCheck_ = 0, struct SPPlugin *self_ = 0, void *globals_ = 0, struct SPBasicSuite *basic_ = 0):   SPCheck(SPCheck_), self(self_), globals(globals_), basic(basic_) {}
#endif/** \c #kSPValidSPMessageData if this is a valid PICA message. */ai::int32 SPCheck;/** This plug-in, an \c #SPPluginRef. */struct SPPlugin *self;/** An array of application-wide global variables. */void *globals;/** A pointer to the basic PICA suite, which you use to obtain all other suites. */struct SPBasicSuite *basic;
};extern "C" ASAPI ASErr PluginMain(char* caller, char* selector, void* message)
{//caller指示消息的发送者(PICA,宿主程序或插件)和动作的通用类型。//selector指定动作类型的执行动作。所有插件收到至少4类消息动作:reload(重新加载),unload(卸载),startup(启动)和shutdown(关系)。此外,插件可能收到特定插件类型的附加消息。//message指针是一个消息数据结构体,它包括这个消息动作的相关信息。如,当一个鼠标点击消息接收到时,消息结构体包括鼠标的位置。消息结构体的内容取决于消息,在你的插件定义这个后,才能知道。由于消息内容不同,按照约定,所有消息结构体由相同字段组成,组合到SPMessageData结构体中。ASErr error = kNoErr;SPMessageData *msgData = (SPMessageData *)message;Plugin *plugin = (Plugin *)msgData->globals;sSPBasic = msgData->basic;/** PICA messaging system caller; see \c #SPInterfaceSuite. *///#define kSPInterfaceCaller                "SP Interface"if (strcmp(caller, kSPInterfaceCaller) == 0) //是否是消息系统调用{ /** PICA messaging system startup; see \c #SPInterfaceSuite.  *///#define kSPInterfaceStartupSelector       "Startup"if (strcmp( selector, kSPInterfaceStartupSelector) == 0)//插件启动{plugin = AllocatePlugin(msgData->self);//全局插件if (plugin){msgData->globals = (void *)plugin;error = plugin->StartupPlugin((SPInterfaceMessage *)message);//插件启动if (error != kNoErr){// Make sure to delete in case startup faileddelete plugin;plugin = nil;msgData->globals = nil;}}else{error = kOutOfMemoryErr;}}else if (strcmp(selector, kSPInterfaceShutdownSelector) == 0)// 插件关闭{if (plugin){error = plugin->ShutdownPlugin((SPInterfaceMessage *)message);//关闭函数           delete plugin;plugin = nil;msgData->globals = nil;}}}if (plugin){if (Plugin::IsReloadMsg(caller, selector))//重载插件{// Call this before calling any virtual functions (like Message)FixupReload(plugin);error = plugin->ReloadPlugin((SPInterfaceMessage *)message);}else{// If a load or reload failed because the suites could not be acquired, we released// any partially acquired suites and returned an error.  However, SuitePea still might// call us, so protect against this situation.if (plugin->SuitesAcquired())error = plugin->Message(caller, selector, message);//消息路由elseerror = kNoErr;}if (error == kUnhandledMsgErr){error = kNoErr;
#ifndef NDEBUG
#ifdef MAC_ENVfprintf(stderr, "Warning: Unhandled plugin message: caller \"%s\" selector \"%s\"\n", caller, selector);
#elsechar buf[1024];sprintf(buf+1, "Warning: Unhandled plugin message: caller \"%s\" selector \"%s\"\n", caller, selector);OutputDebugStringA(buf+1);
#endif
#endif}}    if (error){if (plugin)plugin->ReportError(error, caller, selector, message);//错误elsePlugin::DefaultError(msgData->self, error);}return error;
}

  功能解析都写在注释里,方便读者阅读,在上述入口函数中,涉及到了两个类一个是SPMessageData,它里面有几个参数,见注释,另一个是SPBasicSuite类,代码如下所示:

/*********************************************************************************** Suite****//** @ingroup SuitesThis suite provides basic memory management for PICA (the Adobe plug-in manager)and defines the basic functions for acquiring and releasing other suites.A suite consists of a list of function pointers. The application, or aplug-in that loads a suite, provides valid pointers when the suite isacquired. When a suite is not available, the pointers are set to theaddress of the \c #Undefined() function.Do not attempt to acquire a suite (other than the \c #SPBlocksSuite)in response to a PICA access (\c #kSPAccessCaller) or property(\c #kSPPropertiesCaller) message. Most suites are unavailableduring these load and unload operations.You can acquire all the suites you will need when your plug-in is firstloaded, as long as you release them before your plug-in is unloaded.At shutdown, however, it is most efficient to acquire only thosesuites explicitly needed to shut down; for example, to free memoryand save preferences.The \c SPBasicSuite itself is a part of the message data passedto your plug-in with any call. To access it from the message data structure:@codeSPBasicSuite sBasic = message->d.basic;sBasic->function( )@endcode*/
typedef struct SPBasicSuite {/** Acquires a function suite. Loads the suite if necessary,and increments its reference count. For example:@code
SPErr error;
SPBasicSuite *sBasic = message->d.basic;
AIRandomSuite *sRandom;
sBasic->AcquireSuite( kAIRandomSuite, kAIRandomVersion, &sRandom );@endcode@param name The suite name.@param version The suite version number.@param suite [out] A buffer in which to return the suite pointer.@see \c #SPSuitesSuite::AcquireSuite()*/SPAPI SPErr (*AcquireSuite)( const char *name, ai::int32 version, const void **suite );/** Decrements the reference count of a suite and unloads it when thereference count reaches 0.@param name The suite name.@param version The suite version number.*/SPAPI SPErr (*ReleaseSuite)( const char *name, ai::int32 version );/** Compares two strings for equality.@param token1 The first null-terminated string.@param token2 The second null-terminated string.@return True if the strings are the same, false otherwise.*/SPAPI SPBoolean (*IsEqual)( const char *token1, const char *token2 );/** Allocates a block of memory.@param size The number of bytes.@param block [out] A buffer in which to return the block pointer.@see \c #SPBlocksSuite::AllocateBlock()*/SPAPI SPErr (*AllocateBlock)( size_t size, void **block );/** Frees a block of memory allocated with \c #AllocateBlock().@param block The block pointer.@see \c #SPBlocksSuite::FreeBlock()*/SPAPI SPErr (*FreeBlock)( void *block );/** Reallocates a block previously allocated with \c #AllocateBlock().Increases the size without changing the location, if possible.@param block The block pointer.@param newSize The new number of bytes.@param newblock [out] A buffer in which to return the new block pointer.@see \c #SPBlocksSuite::ReallocateBlock()*/SPAPI SPErr (*ReallocateBlock)( void *block, size_t newSize, void **newblock );/** A function pointer for unloaded suites. This is a protective measureagainst other plug-ins that may mistakenly use the suite after they havereleased it.A plug-in that exports a suite should unload the suite's procedure pointerswhen it is unloaded, and restore them when the plug-in is reloaded.\li On unload, replace the suite's procedure pointerswith the address of this function.\li On reload, restore the suite's procedurepointers with the updated addresses of their functions.For example:@codeSPErr UnloadSuite( MySuite *mySuite, SPAccessMessage *message ) {mySuite->functionA = (void *) message->d.basic->Undefined;mySuite->functionB = (void *) message->d.basic->Undefined;}SPErr ReloadSuite( MySuite *mySuite, SPAccessMessage *message ) {mySuite->functionA = functionA;mySuite->functionB = functionB;}@endcode*/SPAPI SPErr (*Undefined)( void );} SPBasicSuite;

  这是一个加载模块,它实现了模块的加载和卸载,还有内存分配、释放和重新分配功能。

2.作者答疑


  如有疑问,请留言。

illustrator插件开发-AI插件-aip格式-第一章 第二小节 入口点函数相关推荐

  1. 模电笔记二(第一章第二小节)

    文章目录 半导体二极管 一.二极管的组成 二.二极管的伏安特征及电流方程 三.二极管的等效电路 1.折线化 2.微变等效电路 四.二极管的主要参数 五.稳压二极管 1.伏安特性 2.主要参数 半导体二 ...

  2. ASP.NET自定义控件组件开发 第一章 第二篇 接着待续

    ASP.NET自定义控件组件开发 第一章 第二篇 接着待续 ASP.NET自定义控件组件开发 第一章 第二篇 接着待续 很感谢大家给我的第一篇ASP.NET控件开发的支持!在写这些之前,我也看了一些例 ...

  3. 软件构造 第一章第二节 软件开发的质量属性

    ​软件构造 第一章第二节 软件开发的质量属性 1.软件系统质量指标 External quality factors affect users 外部质量因素影响用户 Internal quality ...

  4. 【Git】版本控制管理(第二版) 前言 第一章 第二章

    版本控制管理 前言 第一章 第二章 资源 前言 本书结构 第一章 介绍 总结在开头 1.1 背景 1.2 Git的诞生 1.3 先例 1.4 时间线 第二章 安装Git 2.1 使用Linux上的二进 ...

  5. Day1ps设计基础作业第一章第二章

    Day1 ps设计基础作业第一章第二章 1.1工作区和工作流程 3种调整人像照片亮度的方式:1图像-调整-亮度/对比度,2图像-调整-色阶,3获取图像亮度+混合模式,通道(右下)按ctrl RGB的缩 ...

  6. 第一章第二题(显示五条消息)(Display five messages)

    第一章第二题(显示五条消息)(Display five messages) 1.2(显示五条消息)编写程序,显示 Welcome to Java 五次. 1.2 (Display five messa ...

  7. c语言switch逻辑用语,第一章 第二节用逻辑用语.doc

    第一章 第二节用逻辑用语 第一章 集合与常用逻辑用语 第二节 常用逻辑用语 第一部分 五年高考荟萃 2009年高考题 1.(2009浙江理)已知是实数,则"且"是"且&q ...

  8. 【吃瓜笔记】第一章第二章

    [吃瓜笔记]第一章&第二章 一.基本术语 二.模型评估与选择 1.评估方法 (1).留出法 (2).交叉验证法 (3).自助法 2.选择依据 (1).性能度量 1).错误率与精度 2).查准率 ...

  9. 《网络是怎样连接的》第一章第二节:向DNS服务器查询Web服务器的IP地址

    <网络是怎样连接的>第一章:浏览器生成消息 概述:这本书以 "从在浏览器输入网址,到屏幕显示出网页,当中到底发生了什么?"为疑问,探究其中的过程.本章讲的是浏览器怎么把 ...

最新文章

  1. swift-判断是否已获得相机、相册权限
  2. Insyde uefi 隐藏设置_安卓福利,手机桌面图标隐藏,找应用按字母轻松搞定!
  3. 操作系统中的死锁_操作系统中的死锁介绍
  4. premiere安装失败解决办法
  5. OpenShift Security (8) - 安装并运行 DevSecOps 应用
  6. easyUI的使用.datagrid()生成列表日期时间显示异常,一个方法带入有效修复
  7. python写扫雷脚本_利用Python实现自动扫雷小脚本
  8. 做软件项目经理需要具备的品质和素质
  9. 用matlab实现快速傅里叶变换的源程序,matlab快速傅里叶变换(三个matlab程序介绍)...
  10. Ubuntu 18.04卸载旧版本英伟达显卡驱动
  11. 得了骨关节炎不能吃什么?
  12. iOS 自定义播放器
  13. 由于这台计算机没有远程桌面客户端
  14. 那位仁兄或者仁姐能给小弟一个菊花论坛的邀请码
  15. JAVA 输出杨辉三角形
  16. 微内核相对于单内核优势之我见
  17. Java核心技术 卷1 基础知识 学习笔记——第三章 java的基本程序设计结构
  18. android 开启闪光灯(手电筒)
  19. 基于Python的PyGame实现的横板动作小游戏
  20. 2022最新魔方财务管理系统织音①号模板免费下载,智简魔方免费主题模板下载

热门文章

  1. 安装教程——Stegsolve
  2. cesium模型加载-加载fbx格式模型
  3. Ogre3D Mesh转换到FBX格式
  4. 携程商旅荣膺“年度受企业认可差旅管理公司”
  5. 汇众再观手游市场新风口-二次元游戏
  6. Java SE7新特性之泛型实例创建时的类型推断
  7. 用Python实现ipatables及l7lter的使用
  8. NOIP2018提高组省一冲奖班模测训练(二)
  9. 平面设计中常用制作尺寸
  10. “佛祖保佑永不宕机永无BUG”的文本