c++ DLL相关

来源:互联网 发布:以前很老的网络歌手 编辑:程序博客网 时间:2024/05/22 06:27
DLL:
使动态链接库可以被所有语言,所有编译器使用,则可以在动态链接库的工程文件中加入模板文件.def
.def里面写入
LIBRARY XX.dll


EXPORTS
函数名
函数名





使C++的动态链接库中函数能被C语言调用,则在头文件上加入extern "C" _declspec(dllimport)
#ifdef DLL_API
#else
#define DLL_API extern "C" _declspec(dllimport)
#endif


DLL_API Fun1(xx,xx);
DLL_API Fun2(xx,xx);


class //DLL_API Point(可以定义一个类都是导入的DLL_API)
{
public :
//DLL_API void  xx(xx,xx);(也可以定义一个类中某个方法是导入的DLL_API)
};




加上了头文件之后,DLL的cpp文件中就可以写入
#define DLL_API extern "C" _declspec(dllexport)
#include "DLL.h"


int Fun1(xx,xx)
{
xxxx;
}


int Fun2(xx,xx)
{
xxxx;
}


如果没加头文件,则每个函数开头都要_declspec(dllexport) int Fun1(xx,xx)


typedef int (*FunProc)(xx,xx)
HMOUDLE hInst = LoadLibrary("xx.dll")
FunProc Fun1Proc = GetProAddress(hInst,"Fun1"); //也可以通过序号查找函数地址GetProAddress(hInst,MAKEINTRESOURCE(1))
Fun1Proc(xx,xx);


对于C++的_stdcall,在typedef 函数时候一定要加上函数的调用约定typedef int (_stdcall *FunProc)(xx,xx)
原创粉丝点击