add
增加了 plugin 工程
This commit is contained in:
1 parent
cf87cfe93d
commit
a7eaa8483f
11 files changed
+282
-22
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include "mcp_tool.h"
|
||||
#include "mcp_utils.h"
|
||||
#include "ghc/filesystem.hpp"
|
||||
#include "rxregsvc.h"
|
||||
|
||||
#pragma region mcp_ConfigParser
|
||||
bool mcp_ConfigParser::LoadAndRegister(const std::wstring &jsonFilePath, mcp_Tools ®istry)
|
||||
@@ -50,6 +51,7 @@ bool mcp_ConfigParser::LoadAndRegister(const std::wstring &jsonFilePath, mcp_Too
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" int acrxGetApiVersion();
|
||||
void mcp_ConfigParser::LoadDllTool(const nlohmann::json &toolConfig, const std::wstring &pluginDir, mcp_Tools ®istry)
|
||||
{
|
||||
fs::path dllPath
|
||||
@@ -59,12 +61,53 @@ void mcp_ConfigParser::LoadDllTool(const nlohmann::json &toolConfig, const std::
|
||||
|
||||
if (!fs::exists(dllPath))
|
||||
{
|
||||
AfxMessageBox(CString(_T("[MCP Server]Warning: The DLL file does not exist; the associated tools will not load!\n")) + dllPath.c_str());
|
||||
AfxMessageBox(CString(_T("[MCP Server]Warning: The DLL file does not exist, the associated tools will not load!\n")) + dllPath.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
HMODULE hMod = LoadLibrary(dllPath.c_str());
|
||||
if (!hMod) return;
|
||||
|
||||
|
||||
CString verStr;
|
||||
verStr.Format(_T("Major ver:%d, Minor ver:%d"), ARX, SUB_ARX);
|
||||
CString ver_errMsg;
|
||||
ver_errMsg.Format(
|
||||
CString(_T("[MCP Server]Error: Failed to load the DLL. "))
|
||||
+ CString(_T("Please check whether the version of the ObjectARX SDK used by "))
|
||||
+ CString("the DLL matches the current ARX version(%s).\n"), verStr );
|
||||
|
||||
if (!hMod)
|
||||
{
|
||||
AfxMessageBox(ver_errMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 定义版本校验函数指针
|
||||
typedef int (*GetApiVersionFunc)();
|
||||
GetApiVersionFunc getVerFn = (GetApiVersionFunc)GetProcAddress(hMod, "acrxGetApiVersion");
|
||||
|
||||
// 2. 核心拦截逻辑
|
||||
if (!getVerFn)
|
||||
{
|
||||
// 连这个函数都没导出,说明根本不是合法的 ObjectARX/MCP 插件
|
||||
AfxMessageBox(CString(
|
||||
CString(_T("The ObjectARX version of the DLL could not be determined."))
|
||||
+ CString(_T("Please ensure that the acrxGetApiVersion function is exported."))
|
||||
));
|
||||
FreeLibrary(hMod);
|
||||
return;
|
||||
}
|
||||
|
||||
// 拿 DLL 编译时的 SDK 版本,和基座当前运行的 SDK 版本进行比对
|
||||
int arx_version(acrxGetApiVersion());
|
||||
int dll_version(getVerFn());
|
||||
if (arx_version != dll_version)
|
||||
{
|
||||
// 平台大版本不匹配,强行加载必定闪崩,果断踢掉!
|
||||
FreeLibrary(hMod);
|
||||
AfxMessageBox(ver_errMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
typedef mcp_Tool *(*CreateFunc)();
|
||||
typedef void (*DestroyFunc)(mcp_Tool *);
|
||||
|
||||
Reference in new issue
Block a user