文章目录
本文是系列文章中的一节,有需要的读者,如果阅读时遇到突然出现的符号和术语,可以去前面的章节查找。
1.导出表
- 1.导出表
- 2.界面检测
- 3.作者答疑
illustrate插件本质上是动态链接库,除了有导入表,自然有供宿主软件调用的导出表。这里采用ida打开,转到导出表即可看到。如下图所示: 可以看出,有3个导出函数,一个是PluginMain,插件入口函数,DllEntryPoint 进入点函数。从illustrator SDK中,我们找到了入口点函数PluginMain的调用形式,如下所示:
extern "C" ASAPI ASErr PluginMain(char* caller, char* selector, void* message)
{
ASErr error = kNoErr;
SPMessageData *msgData = (SPMessageData *)message;
Plugin *plugin = (Plugin *)msgData->globals;
sSPBasic = msgData->basic;
if (strcmp(caller, kSPInterfaceCaller) == 0)
{
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 failed
delete 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);
else
error = kNoErr;
}
if (error == kUnhandledMsgErr)
{
error = kNoErr;
#ifndef NDEBUG
#ifdef MAC_ENV
fprintf(stderr, "Warning: Unhandled plugin message: caller \"%s\" selector \"%s\"\n", caller, selector);
#else
char 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);
else
Plugin::DefaultError(msgData->self, error);
}
return error;
}
这个函数由3个参数组成,一个caller调用者名称,一个是selector选择字符串,最后一个是该消息携带的信息。它是与宿主软件调用插件的接口。
2.界面检测 界面有原生窗口界面和DirectUI绘制界面,采用spy++这个工具软件测试一下,如下图所示: 选择箭头所指图标,然后在CAD界面(左侧)上移动,右边会出现相应的参考信息。说明是采用windows原生窗口句柄绘制。
接下来分析CADTools具体功能的实现。
3.作者答疑如有疑问,请留言。
提示: 作者知了-联系方式1 提示: 作者知了-联系方式2