C函数的DLL,C++动态调用。
2016-12-15 10:02
197 查看
1、项目结构
2、建立c项目,其实很简单,只要源文件是.c的即可。
CDLL.h头文件
CDLL.c文件
3、C++动态调用
2、建立c项目,其实很简单,只要源文件是.c的即可。
CDLL.h头文件
#ifndef __CDLL_H__ #define __CDLL_H__ extern int _declspec(dllexport) foo(int x, int y); #endif
CDLL.c文件
#include "CDLL.h" int foo(int x, int y) { return x + y; }
3、C++动态调用
#include "DLLDemo.h" #include<iostream> #include<Windows.h> using namespace std; typedef int(*lp)(int, int); int main() { HINSTANCE hdll; lp func; hdll = LoadLibrary("CDLL.dll"); //或者:hdll = LoadLibrary("../Debug/CDLL.dll"); 要保证相对路径正确 if (hdll != NULL) { func = (lp)GetProcAddress(hdll, "foo"); cout << func(2, 3) << endl; } FreeLibrary(hdll); return 0; }
相关文章推荐
- 在Delphi中动态调用C++的DLL
- C#动态调用C++的Dll
- Java使用JNI调用C/C++的DLL动态链接库1
- C++ 编写DLL 动态及静态调用DLL方法
- 在C++中调用DLL中的函数——静态调用和动态调用
- 在Delphi中动态调用C++的DLL
- java如何调用dll:用JNI调用C或C++动态联接库原来如此简单
- C++对dll链接库的显示(动态)调用和隐式(静态)调用
- Java使用JNI调用C/C++的DLL动态链接库2
- 编写S-Function,创建Simulink模型并生成C++代码,编译生成可调用的动态库dll(From Simulink model to DLL A tutorial)
- C#动态调用c++DLL的方法
- c++调用matlab生成的Dll动态连接库
- Windows 下java调用C++ dll动态链接库
- c++ 注册表操作dll动态调用
- C#动态调用C++DLL
- vb.net静态动态调用c++dll的方法
- Java调用C/C++编写的第三方dll动态链接库
- C++ dll调用-动态(显式)
- Java调用C/C++编写的第三方dll动态链接库
- bcb平台的C++dll的静态调用法和动态调用法的方法