当前位置: 首页 > news >正文

C++插件管理系统

插件加载目录结构

execute
    plug.exe
    plugify.dll
    plugify.pconfig
    res
        cpp-lang-module.pmodule
        example_plugin.pplugin
        bin
            cpp-lang-module.dll
            example_plugin.dll

 plugify.pconfig

{
    "baseDir": "res",
    "logSeverity": "debug",
    "repositories": [
    ],
    "preferOwnSymbols": false
}

example_plugin.pplugin

{
    "fileVersion": 1,
    "version": 1,
    "versionName": "1.0",
    "friendlyName": "PluginCPP",
    "description": "An example of a plugin. This can be used as a starting point when creating your own plugin.",
    "createdBy": "untrustedmodders",
    "createdByURL": "https://github.com/untrustedmodders/",
    "docsURL": "https://github.com/orgs/untrustedmodders/README.md",
    "downloadURL": "https://github.com/orgs/untrustedmodders/example-repo.zip",
    "updateURL": "https://github.com/untrustedmodders/plugify/issues",
    "entryPoint": "bin/example_plugin",
    "supportedPlatforms": [],
    "languageModule": {
        "name": "cpp"
    },
    "dependencies": [],
    "exportedMethods": [
        {
            "name": "MakePrint",
            "funcName": "MakePrint",
            "paramTypes": [
                {
                    "type": "int32",
                    "name": "count"
                },
                {
                    "type": "string",
                    "name": "message"
                }
            ],
            "retType": {
                "type": "void"
            }
        }
    ]
}

 cpp-lang-module.pmodule

{
    "fileVersion": 1,
    "version": 0,
    "versionName": "v0",
    "friendlyName": "Cpp language module",
    "language": "cpp",
    "description": "Adds support for C++ plugins",
    "createdBy": "untrustedmodders",
    "createdByURL": "https://github.com/untrustedmodders/",
    "docsURL": "https://github.com/untrustedmodders/cpp-lang-module/blob/main/README.md",
    "downloadURL": "https://github.com/untrustedmodders/cpp-lang-module/releases/download/v0/cpp-lang-module.zip",
    "updateURL": "https://untrustedmodders.github.io/cpp-lang-module/cpp-lang-module.json",
    "supportedPlatforms": [],
    "forceLoad": false
}

 插件定义
#include <plugify/cpp_plugin.h>
#include <plugin_export.h>
#include <iostream>class ExamplePlugin : public plugify::IPluginEntry {
public:void OnPluginStart() override {std::cout << "Example Start!" << std::endl;}void OnPluginEnd() override {std::cout << "Example End!" << std::endl;}void MakePrint(int count, const std::string& message) {for (int i = 0; i < count; ++i) {std::cout << message << std::endl;}}
} g_examplePlugin;EXPOSE_PLUGIN(PLUGIN_API, &g_examplePlugin)extern "C"
PLUGIN_API void MakePrint(int count, const std::string& message) {g_examplePlugin.MakePrint(count, message);
}
 模块定义

#include <plugify/assembly.h>
#include <plugify/module.h>
#include <plugify/plugin.h>
#include <plugify/plugify_provider.h>
#include <plugify/language_module.h>
#include <plugify/cpp_plugin.h>#include <module_export.h>
#include <unordered_map>
#include <map>
#include <array>class CppLanguageModule final : public plugify::ILanguageModule {
public:CppLanguageModule() = default;// ILanguageModuleplugify::InitResult Initialize(std::weak_ptr<plugify::IPlugifyProvider> provider, plugify::ModuleRef module) override;void Shutdown() override;void OnMethodExport(plugify::PluginRef plugin) override;plugify::LoadResult OnPluginLoad(plugify::PluginRef plugin) override;void OnPluginStart(plugify::PluginRef plugin) override;void OnPluginEnd(plugify::PluginRef plugin) override;bool IsDebugBuild() override;const std::shared_ptr<plugify::IPlugifyProvider>& GetProvider() { return _provider; }plugify::MemAddr GetNativeMethod(std::string_view methodName) const;void GetNativeMethod(std::string_view methodName, plugify::MemAddr* addressDest);private:std::shared_ptr<plugify::IPlugifyProvider> _provider;std::map<plugify::UniqueId, AssemblyHolder> _assemblyMap;std::unordered_map<std::string, plugify::MemAddr, string_hash, std::equal_to<>> _nativesMap;std::vector<plugify::MemAddr*> _addresses;static std::array<void*, 15> _pluginApi;
};// ILanguageModule
InitResult CppLanguageModule::Initialize(std::weak_ptr<IPlugifyProvider> provider, ModuleRef /*module*/) {if (!(_provider = provider.lock())) {return ErrorData{ "Provider not exposed" };}_provider->Log("[CPPLM]  Inited!", Severity::Debug);return InitResultData{};
}
 测试
plug.exe
plugify init
[+] Info: Plugify Init!
[+] Info: Version: 1.0.0.0
[+] Info: Git: [v35-1-g08987de]:(v35) - Fix cmake typo in test on main at 'Sun Sep 1 09:21:31 2024'
[+] Info: Compiled on: Windows-10.0.19045 from: Ninja with: 'MSVC'
[~] Debug: Loading local packages
[~] Debug: Loading remote packages
[#] Error: Packages manifest from 'https://github.com/untrustedmodders/plugify/issues' has JSON parsing error: 8:1: expected_brace<!DOCTYPE html>^
[~] Debug: PackageManager loaded in 788.826ms
[~] Debug: [CPPLM] Inited!
Example Start!
[~] Debug: PluginManager loaded in 10.951ms
 参考

GitHub - untrustedmodders/cpp-lang-module: C++ Language Module


 

创作不易,小小的支持一下吧!

http://www.lryc.cn/news/433776.html

相关文章:

  • MyBatis 方法重载的陷阱及解决方案
  • STM32 ADC+DMA导致写FLASH失败
  • Python AttributeError: ‘dict_values’ object has no attribute ‘index’
  • 三丰云免费虚拟主机和免费云服务器评测
  • iOS18更新暂停卡住?iOS18升级失败解决办法分享
  • 单片机软件工程师确认硬件
  • 乐鑫无线WiFi芯片模组,家电设备智能联网新体验,启明云端乐鑫代理商
  • 小米嵌入式面试题目RTOS面试题目 嵌入式面试题目
  • Iceberg与SparkSQL写操作整合
  • MYSQL1
  • 一文解答Swin Transformer + 代码【详解】
  • Vue3:<Teleport>传送门组件的使用和注意事项
  • 项目之家:又一家项目信息发布合作对接及一手接单平台
  • 02-java实习工作一个多月-经历分享
  • JVM 调优篇2 jvm的内存结构以及堆栈参数设置与查看
  • 微信可以设置自动回复吗?
  • 同样数据源走RTMP播放延迟低还是RTSP低?
  • @开发者极客们,网易2024低代码大赛来啦
  • 数据分析-16-时间序列分析的常用模型
  • SpringMVC使用:类型转换数据格式化数据验证
  • 多语言ASO – 本地化的10个技巧
  • C程序设计——函数0
  • 第二十一章 rust与动静态库的结合使用
  • 修改服务器DNS解析及修改自动对时时区
  • 中科院TOP“灌水神刊”合集!盘点那些“又牛又水”的国人友好SCI
  • Python列表浅拷贝的陷阱与破解之道
  • 开放式系统互连(OSI)模型的实际意义
  • 回溯——10.全排列 II
  • 基于百度AIStudio飞桨paddleRS-develop版道路模型开发训练
  • 【 C++ 】C/C++内存管理