增加了 plugin 工程
This commit is contained in:
gjm committed 2026-10-02 23:43:18 +08:00
1 parent cf87cfe93d
commit a7eaa8483f
11 files changed
+282 -22

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ set(SOURCES
"cad_mcp_frame.rc"
"mcp_server.cpp"
"mcp_tool.cpp"
"mcp_ConfigParser.cpp"
"mcp_configParser.cpp"
"mcp_utils.cpp"
)
add_def_file_name(SOURCES "${PROJECT_NAME}")
+45 -2
View File
@@ -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 &registry)
@@ -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 &registry)
{
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 *);
+6 -6
View File
@@ -39,7 +39,7 @@ namespace
}
}
#pragma region mcp_Tool_LispInline
#pragma region LispInline
nlohmann::json mcp_Tool_LispInline::Execute(const nlohmann::json &args)
{
std::string tpl = m_config["backend"].value("script_template", "");
@@ -55,9 +55,9 @@ nlohmann::json mcp_Tool_LispInline::Execute(const nlohmann::json &args)
return mcp_Tool_Utility::make_text_result("LISP inline command issued for execution (asynchronous)");
}
#pragma endregion mcp_Tool_LispInline
#pragma endregion LispInline
#pragma region mcp_Tool_LispFile
#pragma region LispFile
nlohmann::json mcp_Tool_LispFile::Execute(const nlohmann::json &args)
{
fs::path filePath
@@ -86,9 +86,9 @@ nlohmann::json mcp_Tool_LispFile::Execute(const nlohmann::json &args)
return mcp_Tool_Utility::make_text_result("LISP external file loaded and issued for execution (asynchronous)");
}
#pragma endregion mcp_Tool_LispFile
#pragma endregion LispFile
#pragma region mcp_Tool_DllProxy
#pragma region DllProxy
// RAII:基座销毁工具时,自动通知 DLL 释放内存,并卸载模块
mcp_Tool_DllProxy::~mcp_Tool_DllProxy()
{
@@ -110,5 +110,5 @@ nlohmann::json mcp_Tool_DllProxy::Execute(const nlohmann::json &args)
}
return mcp_Tool_Utility::make_error(-32603, "Underlying DLL tool instance is invalid");
}
#pragma endregion mcp_Tool_DllProxy
#pragma endregion DllProxy
+13
View File
@@ -19,6 +19,19 @@ namespace mcp_utils
return wstrTo;
}
std::string WStringToUtf8(const std::wstring &wstr)
{
if (wstr.empty()) return std::string();
// 第一次调用获取需要的 UTF-8 缓冲区大小
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo(sizeNeeded, 0);
// 第二次调用真正进行转换
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], sizeNeeded, NULL, NULL);
return strTo;
}
bool mcp_utils::hasFileExist(const std::wstring &filePath) { return _taccess(filePath.c_str(), 0) == 0; }
bool mcp_utils::hasDirExist(const std::wstring &filePath) { return _taccess(filePath.c_str(), 0) == 0; }