-
-
Notifications
You must be signed in to change notification settings - Fork 0
API Loader
3cxc edited this page Sep 12, 2026
·
2 revisions
Plugin loading and management.
| Type | Description |
|---|---|
PluginLoader |
负责加载和管理插件的核心类。 |
public class PluginLoader负责加载和管理插件的核心类。使用非托管代码 (LoadLibrary) 动态加载插件并调用其导出函数。
public PluginLoader(Action<string> logAction, HostApiTable apiTable, Version apiVersion)初始化 PluginLoader 类的新实例。
| Parameter | Type | Description |
|---|---|---|
logAction |
Action<string> |
用于接收日志消息的委托 |
apiTable |
HostApiTable |
要传递给插件的主程序 API 函数表 |
apiVersion |
Version |
主程序的 API 版本 |
| Member | Type | Description |
|---|---|---|
Api |
HostApiTable |
主程序暴露给插件的 API 函数表 |
CurrentApiVersion |
Version |
主程序的 API 版本,用于与插件所需版本比较 |
LogWriter |
Action<string> |
主程序的日志输出委托,用于记录加载过程信息 |
public bool LoadPlugin(string dllPath)加载指定路径的插件,并调用其导出的 OnInit 函数。
| Parameter | Type | Description |
|---|---|---|
dllPath |
string |
插件的完整路径 |
Returns: 如果加载并初始化成功,返回 true;否则返回 false。
加载成功后模块句柄会保留,以便插件在宿主进程生命周期内保持加载状态。初始化函数指针类型为 delegate* unmanaged<IntPtr, void>。
public void LoadPluginsFromDirectory(string directoryPath)加载指定目录下的所有插件 (*.dll)。
| Parameter | Type | Description |
|---|---|---|
directoryPath |
string |
插件目录路径 |
若目录不存在则静默返回。每个 DLL 的加载过程会通过 LogWriter 记录。
public void UnloadAll()卸载所有已加载的插件并释放库句柄。