使用显示方式调用DLL实现浮点数的四则运算
2010-12-23 13:53
561 查看
先说下我们的调用代码:
在初始化中:
GetDlgItem(IDC_Num1)->SetWindowText("");
GetDlgItem(IDC_Num2)->SetWindowText("");
GetDlgItem(IDC_result)->SetWindowText("0");
在主要实现函数中:
void CUseFloatCallDLLDlg::OnCal()
{
typedef float (*MyCalculate)(float ,float,,int );//宏定义floatcalculate函数指针类型
HINSTANCE hdll; //DLL的句柄
Mycalculate calfunc; //函数指针
hdll.LoadLibrary("..//Debug//FloatCallDLL.dll");//LoadLibrary函数装载DLL
//或者 hdll.LoadLibrary("F://c++项目编程//UseFloatCallDLL//Debug//FloatCallDLL.dll");
if(hdll!=null)
{
calfunc=(Mycalculate)GetProcAddress(hdll,"floatcalculate");
}
else
{
AfxMessgeBox("无法加载DLL");
return;
}
Updatedata(turn);
m_floResult=calfunc(m_floNum1,m_floNum2,m_radio);//调用DLL函数进行计算
Updatedata(false);
FressLibrary(hdll);//释放DLL
}
void CUseFloatCallDLLDlg::Oncheng()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_radio=2;
UpdateData(FALSE);
}
void CUseFloatCallDLLDlg::Onchu()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_radio=3;
UpdateData(FALSE);
}
void CUseFloatCallDLLDlg::Onjia()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_radio=0;
UpdateData(FALSE);
}
void CUseFloatCallDLLDlg::Onjian()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_radio=1;
UpdateData(FALSE);
}
在dll文件中:
在calculate.h中:
extern "C" float _declspec(dllexport)floatcalculate(float x,float y,int type);
在calculate.cpp中
#include "calculate.h"
float floatcalculate(float x,float,y,int type)
{
switch(type)
{
case 0:
{ retutn x+y;}
case 1:
{return x-y;}
case 2;
{return x*y;}
case 3:
{return x/y;}
}
}
在初始化中:
GetDlgItem(IDC_Num1)->SetWindowText("");
GetDlgItem(IDC_Num2)->SetWindowText("");
GetDlgItem(IDC_result)->SetWindowText("0");
在主要实现函数中:
void CUseFloatCallDLLDlg::OnCal()
{
typedef float (*MyCalculate)(float ,float,,int );//宏定义floatcalculate函数指针类型
HINSTANCE hdll; //DLL的句柄
Mycalculate calfunc; //函数指针
hdll.LoadLibrary("..//Debug//FloatCallDLL.dll");//LoadLibrary函数装载DLL
//或者 hdll.LoadLibrary("F://c++项目编程//UseFloatCallDLL//Debug//FloatCallDLL.dll");
if(hdll!=null)
{
calfunc=(Mycalculate)GetProcAddress(hdll,"floatcalculate");
}
else
{
AfxMessgeBox("无法加载DLL");
return;
}
Updatedata(turn);
m_floResult=calfunc(m_floNum1,m_floNum2,m_radio);//调用DLL函数进行计算
Updatedata(false);
FressLibrary(hdll);//释放DLL
}
void CUseFloatCallDLLDlg::Oncheng()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_radio=2;
UpdateData(FALSE);
}
void CUseFloatCallDLLDlg::Onchu()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_radio=3;
UpdateData(FALSE);
}
void CUseFloatCallDLLDlg::Onjia()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_radio=0;
UpdateData(FALSE);
}
void CUseFloatCallDLLDlg::Onjian()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_radio=1;
UpdateData(FALSE);
}
在dll文件中:
在calculate.h中:
extern "C" float _declspec(dllexport)floatcalculate(float x,float y,int type);
在calculate.cpp中
#include "calculate.h"
float floatcalculate(float x,float,y,int type)
{
switch(type)
{
case 0:
{ retutn x+y;}
case 1:
{return x-y;}
case 2;
{return x*y;}
case 3:
{return x/y;}
}
}
相关文章推荐
- 使用隐式方式调用DLL实现浮点数的四则运算
- C++ budilder 使用ImageOle.dll 实现richedit显示任意格式图片和连接 gif
- 12-界面控件之listView使用java代码和xml文件不同方式实现列表显示
- 使用注解方式实现Dubbo搭建,解决消费者调用接口出现空指针异常以及事务等问题
- 使用JNI技术实现JAVA程序调用dll
- 使用COM方式实现不同语言之间的调用
- 通过COM组件方式实现java调用C#写的DLL文件
- AutoCAD.NET 不使用P/Invoke方式调用acad.exe或accore.dll中的接口(如acedCommand、acedPostCommand等)
- 8、使用Struts2实现异步调用机制剖析(XML与JSON方式解析)
- JSP+jquery使用ajax方式调用json的实现方法
- 使用JNI技术实现JAVA程序调用dll
- VC++ .NET 动态加载DLL,使用反射方式Invoke委托调用
- 使用JNI技术实现JAVA程序调用dll
- 使用接口的方式调用远程服务 ------ 利用动态调用服务,实现.net下类似Dubbo的玩法。
- 使用URL工具类调用webservice接口(soap)与http接口的实现方式
- paip. c++ 调用.net dll 最好方式powershell 使用总结.
- C#反射动态调用dll中的方法及使用QuartZ.net实现作业调度
- 使用“事件监听/链式事件处理方式”实现window.onload同时调用多个函数
- 使用 Jni 调用 Dll 的实现JAVA在cmd控制台刷屏