链接库dll-6-简单插件
来源:互联网 发布:mobi的域名含义 编辑:程序博客网 时间:2024/06/05 07:15
***************************************链接库代码:
ImgArithPlugBase.h
#pragma once#ifndef ImgArithPlugBase_LK#define ImgArithPlugBase_LK#include <string>typedef int ImgArithInputType;typedef int ImgArithOutputType;class ImgArithPlugBase{public:virtual std::string description() const = 0;virtual bool validate(const ImgArithInputType& input) const = 0;virtual bool process( const ImgArithInputType& input , ImgArithOutputType& output) = 0;virtual ~ImgArithPlugBase(){}};#endif
插件文件ImgArithPlugAdd.cpp
#include "ImgArithPlugBase.h"#include <laok.h>#include <boost/config.hpp> // for BOOST_SYMBOL_EXPORTclass ImgArithPlugAdd : public ImgArithPlugBase{public:virtual std::string description() const {return "output = input + 200";}virtual bool validate(const ImgArithInputType& input) const {return input > 0;}virtual bool process( const ImgArithInputType& input , ImgArithOutputType& output){output = input + 200;return true;}};extern "C" BOOST_SYMBOL_EXPORT ImgArithPlugAdd plugin;ImgArithPlugAdd plugin;
导出控制dllmain.cpp
#include <iostream>#include <boost/dll.hpp>#include <Windows.h>namespace dll = boost::dll;int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved){std::string location = dll::this_line_location().string();if (pvReserved)std::cout << location << "********************************loaded implicit!\n" ;elsestd::cout << location << "********************************loaded explicit!\n";switch(fdwReason) {case DLL_PROCESS_ATTACH:std::cout << location << "********************************dll process attach\n";//系统在进程空间映射break;case DLL_PROCESS_DETACH:std::cout << location << "********************************dll process detach\n" ;//系统在进程空间撤销break;case DLL_THREAD_ATTACH:std::cout << location << "********************************dll thread attach\n" ;//主线程不会触发,进程创建线程时,通知每一个dllmain,然后执行线程函数break;case DLL_THREAD_DETACH:std::cout << location << "********************************dll thread detach\n" ;//线程正常终止时候,触发break;}return TRUE ;}
***************************************测试代码:
ImgArithPlugAdd-test.cpp
#include <boost/dll.hpp>#include <laok.h>#include "ImgArithPlugBase.h"namespace dll = boost::dll;JOB_DEFINE(dll_app , ImgArithPlugAdd){boost::filesystem::path libpath = GetCurFilePath();libpath /= "ImgArithPlugAdd.dll";boost::shared_ptr<ImgArithPlugBase> plug = dll::import<ImgArithPlugBase>(libpath , "plugin");PS( plug->description() );ImgArithInputType input;ImgArithOutputType output;input = 10;PS(input);PS( plug->validate(input) );PS( plug->process(input , output) );PS(output);}
测试效果:
=====<dll_app_ImgArithPlugAdd>beginE:\ArgusTech\workspace-cpp\boost\dll\app\ImgArithPlugAdd.dll********************************loaded explicit!E:\ArgusTech\workspace-cpp\boost\dll\app\ImgArithPlugAdd.dll********************************dll process attach[plug->description()]:[output = input + 200][input]:[10][plug->validate(input)]:[true][plug->process(input , output)]:[true][output]:[210]E:\ArgusTech\workspace-cpp\boost\dll\app\ImgArithPlugAdd.dll********************************loaded explicit!E:\ArgusTech\workspace-cpp\boost\dll\app\ImgArithPlugAdd.dll********************************dll process detach=====<dll_app_ImgArithPlugAdd>end [State:OK] [Times:0.049s]
0 0
- 链接库dll-6-简单插件
- 动态链接库 简单的DLL (转载)
- 动态链接库(DLL)简单了解
- dll动态链接库简单入门
- 简单dll动态链接库的建立和应用
- VC++MFC 简单的DLL加载动态链接库
- 编写DLL(动态链接库)的简单流程
- 四. 一个简单的DLL(非MFC动态链接库)
- dll入门简单实例(动态链接库)
- 动态链接库(DLL)总结---简单使用(1)
- 动态链接库(DLL)总结---简单使用(2)
- 动态链接库 (DLL)
- 动态链接库DLL
- 动态链接库DLL
- 动态链接库 dll
- 链接库【DLL】
- DLL动态链接库
- DLL 动态链接库
- 30.JDBC连接Oracle数据库的步骤
- PUPPET安装配置MCollective+ActiveMQ——详细指导
- java 遍历数组
- SDL基础-1、搭建开发环境(CB)
- Ubuntu常用软件安装
- 链接库dll-6-简单插件
- C语言申请内存时堆栈大小限制
- Redis数据类型及其操作
- FreeRTOS内核详解—-Queue
- 31.JDBC中的PreparedStatement和Statement
- Nginx架设能流媒体服务器
- kubernetes容器编排系统介绍
- 不同平台(mac、windows—wpf、web、ios、android)下实现页面的转场动画
- Android网络编程之使用HttpClient和MultipartEntityBuilder 批量同时上传文件和文字