显示调用c++动态链接库
来源:互联网 发布:搜索字幕的软件 编辑:程序博客网 时间:2024/06/05 05:39
1.动态链接库生成
<span style="background-color: rgb(255, 255, 255);">//operator.h#ifndef OPERATOR_H#define OPERATOR_H#include <stdio.h>#include <stdlib.h>#ifdef __cplusplusextern "C"{#endifint Add(int a, int b);int Sub(int a, int b);#ifdef __cplusplus}#endif#endif</span>
<span style="background-color: rgb(255, 255, 255);"></span>
<pre name="code" class="html"><span style="background-color: rgb(255, 255, 255);">//operator.cpp#include "operator.h"int Add(int a, int b){return a + b;}int Sub(int a, int b){return a - b;}</span>
<pre name="code" class="html">//operator_dll.h#ifndef _OPERATOR_DLL_H#define _OPERATOR_DLL_H#define DLLEXPORT __declspec(dllexport)extern "C" DLLEXPORT int Operator(int a, int b, int *result);#endif//operator_dll.cpp
#include "operator_dll.h"#include "operator.h"DLLEXPORT int Operator(int a, int b, int *result){*result = Add(a, b) + Sub(a, b);if (result){return 1;}else{return 0;}}
//test_main#include "operator_dll.h"#include <stdio.h>int main(void){int a, b, result;a= 4;b = 3; Operator(a, b, &result);printf("operator result : %d \n", result);return 0;}
2.动态链接库的调用
<pre name="code" class="html">#include <Windows.h>#include <string>using namespace std;typedef int (*OperatorFunc)(int ,int ,int* );void test_operator_dll(){int result;result = 0;OperatorFunc _OperatorFunc;HMODULE handle = LoadLibrary("mydll.dll");if (handle){_OperatorFunc = (OperatorFunc)GetProcAddress(handle, "Operator");if (_OperatorFunc){_OperatorFunc(4, 3, &result);printf("result = %d", result);}else{printf("GetProcAddress() is failed : %d\n", GetLastError());}FreeLibrary(handle);}else{printf("LoadLibrary() is failed : %d \n", GetLastError());}}int main(void){test_operator_dll();return 1;}
3.运行结果:
result = 8
0 0
- 显示调用动态链接库
- 显示调用c++动态链接库
- 标准C调用C++动态链接库
- Java调用c/c++动态链接库
- C#调用C/C++动态链接库
- Python调用C/C++动态链接库
- Python调用C/C++动态链接库
- C调用GO的动态链接库
- JNA调用C语言动态链接库
- 【c#】C#调用matlab动态链接库
- erlang调用c\c++动态链接库
- Python调用C语言之如何调用动态链接库
- C调用C++动态库以及静态链接库
- ctypes: 使用python调用C编写的动态链接库
- C/C++中动态链接库的创建和调用
- C/C++中动态链接库的创建和调用
- C/C++中动态链接库的创建和调用
- C/C++中动态链接库的创建和调用
- TCP的SACK选择确认选项
- Oozie4.2 安装部署、以及example测试
- 【练习笔记】剑指offer-面试题8 :旋转数组的最小数字
- Android Adapter优化问题
- 初试贪心nyoj6喷水装置(一)
- 显示调用c++动态链接库
- Integer to Roman
- HDU 4355 数轴上的点找使Si^3*Wi最小的和-浮点数三分
- java多线程之 ---- 线程同步
- error LNK2019: 无法解析的外部符号 __imp__CryptBinaryToStringA@20
- c 总结
- Android图片缓存库使用经验总结
- Cookie与Session的区别与联系及生命周期
- 一键安装PPTP服务