从动态链接库中导出类
2010-11-25 17:53
176 查看
贴代码。
dll的代码
class.h文件
class CMath
{
public:
int _declspec(dllexport) GetMaxConnDiv(int a,int b);
int _declspec(dllexport) GetMinConnDiv(int a,int b);
};
class.def文件
LIBRARY class
EXPORTS
GetMaxConnDiv
GetMinConnDiv
class.cpp文件
#include"class.h"
int CMath::GetMaxConnDiv(int a , int b)
{
int x=1;
int ires;
if(a<b)
return 0;
if(b==0)
return 0;
while(x!=0)
{
x=a%b;
a=b;
ires=b;
b=x;
}
return ires;
}
int CMath::GetMinConnDiv(int a, int b)
{
int x=1;
int ires;
int m,n;
m=a;
n=b;
if(a<b)
return 0;
if(a==0)
return 0;
if(b==0)
return 0;
while(x!=0)
{
x=a%b;
a=b;
ires=b;
b=x;
}
ires=(m*n)/ires;
return ires;
}
测试程序文件
void CTextdllDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str1,str2;
m_edit3.GetWindowText(str1);
m_edit4.GetWindowText(str2);
int m,n;
m=atoi(str1);
n=atoi(str2);
int re;
CString result;
typedef int (WINAPI * MyFunc)(int ,int );//必需加上WINAPI,不然会出错
HMODULE hModule=::LoadLibrary("class.dll");
MyFunc Getval=(MyFunc)GetProcAddress(hModule,"GetMaxConnDiv");
re=Getval(m,n);
result.Format("%d",re);
m_edit1.SetWindowText(result);
FreeLibrary(hModule);
}
void CTextdllDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CString str1,str2;
m_edit3.GetWindowText(str1);
m_edit4.GetWindowText(str2);
int m,n;
m=atoi(str1);
n=atoi(str2);
int re;
typedef int (WINAPI * MyFunc) (int ,int );
HMODULE hModule=::LoadLibrary("class.dll");
MyFunc Getval=(MyFunc)GetProcAddress(hModule,"GetMinConnDiv");
re=Getval(m,n);
CString result;
result.Format("%d",re);
m_edit2.SetWindowText(result);
FreeLibrary(hModule);
}
dll的代码
class.h文件
class CMath
{
public:
int _declspec(dllexport) GetMaxConnDiv(int a,int b);
int _declspec(dllexport) GetMinConnDiv(int a,int b);
};
class.def文件
LIBRARY class
EXPORTS
GetMaxConnDiv
GetMinConnDiv
class.cpp文件
#include"class.h"
int CMath::GetMaxConnDiv(int a , int b)
{
int x=1;
int ires;
if(a<b)
return 0;
if(b==0)
return 0;
while(x!=0)
{
x=a%b;
a=b;
ires=b;
b=x;
}
return ires;
}
int CMath::GetMinConnDiv(int a, int b)
{
int x=1;
int ires;
int m,n;
m=a;
n=b;
if(a<b)
return 0;
if(a==0)
return 0;
if(b==0)
return 0;
while(x!=0)
{
x=a%b;
a=b;
ires=b;
b=x;
}
ires=(m*n)/ires;
return ires;
}
测试程序文件
void CTextdllDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str1,str2;
m_edit3.GetWindowText(str1);
m_edit4.GetWindowText(str2);
int m,n;
m=atoi(str1);
n=atoi(str2);
int re;
CString result;
typedef int (WINAPI * MyFunc)(int ,int );//必需加上WINAPI,不然会出错
HMODULE hModule=::LoadLibrary("class.dll");
MyFunc Getval=(MyFunc)GetProcAddress(hModule,"GetMaxConnDiv");
re=Getval(m,n);
result.Format("%d",re);
m_edit1.SetWindowText(result);
FreeLibrary(hModule);
}
void CTextdllDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CString str1,str2;
m_edit3.GetWindowText(str1);
m_edit4.GetWindowText(str2);
int m,n;
m=atoi(str1);
n=atoi(str2);
int re;
typedef int (WINAPI * MyFunc) (int ,int );
HMODULE hModule=::LoadLibrary("class.dll");
MyFunc Getval=(MyFunc)GetProcAddress(hModule,"GetMinConnDiv");
re=Getval(m,n);
CString result;
result.Format("%d",re);
m_edit2.SetWindowText(result);
FreeLibrary(hModule);
}
相关文章推荐
- 编译VC++类的动态链接库DLL 导出类及其中的函数
- 动态链接库
- 动态加载链接库方法
- 动态链接库之延迟绑定探究
- 动态链接库dll,静态链接库lib, 导入库lib
- 创建新的动态链接库 (DLL) 项目
- 【Debug】无法定位序数9965于动态链接库mfc90u.dll上
- 解决:开机提示找不到iertutil.dll,无法定位序数681于动态链接库iertutil.dll上
- 动态库链接问题
- VC++如何创建与调用动态链接库
- 利用Webkit抓取动态网页和链接
- 动态链接库dll,静态链接库lib, 导入库lib
- Qt 5 在 Mac 下使用 HomeBrew 的动态链接库的问题
- 【C++】linux下CMake生成动态链接库,g++包含生成动态链接库
- gcc静态链接与动态链接,gdb test,$^依赖$@目标$<
- 无法定位程序输入点 于动态链接库
- VC中隐式链接无.LIB动态链接库的方法
- 转一篇关于二维数组动态分配的文章,可以结合链接的文章
- h头文件 .lib动态链接库文件 .dll 动态链接库
- Android编译加入第三方动态链接库文件的方法