15,471
社区成员
发帖
与我相关
我的任务
分享
void CDllTestDlg::OnBtnAdd()
{
// TODO: Add your control notification handler code here
HINSTANCE hInst;
hInst = LoadLibrary("Dll2.dll");
typedef int (* ADDPROC)(int a,int b);
ADDPROC Add = (ADDPROC) GetProcAddress(hInst,"add");
if(!Add)
{
MessageBox("获取函数地址失败!");
return ;
}
CString str;
str.Format("5+3=%d",Add(5,3));
MessageBox(str);
FreeLibrary(hInst);
}
void CDllTestDlg::OnBtnAdd() //点击按钮,显示5+3的值
{
// TODO: Add your control notification handler code here
HINSTANCE hInst;
hInst = LoadLibrary("Dll2.dll");
typedef int (* ADDPROC)(int a,int b);
ADDPROC Add = (ADDPROC) GetProcAddress(hInst,"add");
if(!Add)
{
MessageBox("获取函数地址失败!");
return ;
}
CString str;
str.Format("5+3=%d",Add(5,3));
MessageBox(str);
FreeLibrary(hInst);
}
int add(int a,int b)
{
return a + b ;
}
int subtract(int a,int b)
{
return a - b ;
}
LIBRARY Dll2 //.dll名
EXPORTS
add
subtract