15,471
社区成员
发帖
与我相关
我的任务
分享
/*************************main.h****************************/
#ifndef DLL_API
#define DLL_API _declspec(dllimport)
#endif
DLL_API int add(const int a,const int b);
/*************************main.cpp**************************/
#define DLL_API _declspec(dllexport)
#include "main.h"
int add(const int a,const int b)
{
return a+b;
}
//对话框按钮“加法”(ID为IDC_BUTTON1)的消息响应
void CTestDll2Dlg::OnButton1()
{
HINSTANCE hDll=LoadLibrary("Dll2.dll");
if(!hDll)
{
MessageBox("加载动态链接库失败!");
return;
}
typedef int (*pAddProc)(const int a,const int b);
pAddProc add=(pAddProc)GetProcAddress(hDll,"add");
if(!add)
{
MessageBox("找不到指定函数!");
return;
}
CString str;
str.Format("3+5=%d",add(3,5));
MessageBox(str);
FreeLibrary(hDll);
}
pAddProc add=(pAddProc)GetProcAddress(hDll,"add");
pAddProc add=(pAddProc)GetProcAddress(hDll,"?add@@YAHHH@Z");
#define DLL_API extern "C" _declspec(dllexport)