VC调用Delphi DLL
2014-02-25 04:46
274 查看
别的没什么,是一定可以调用成功的。但是意外的是,ShowMessage函数在DLL里也可以轻易被调用。此外,Delphi里的var 相当于VC里的引用,需要在函数原型里正确标识,否则传递普通变量甚至常量是不行的。
VC++代码:
Delphi代码(代码太多,只列举关键函数实现部分):
另外,VC里可能默认使用cdecl方式。我没写传递方式就可以成功调用。
VC++代码:
// callDLL.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "windows.h" int main(int argc, char* argv[]) { printf("Hello World!\n"); double a=10.4; HINSTANCE hDllInst = LoadLibrary("fonctionMathematique.DLL"); if(hDllInst) { typedef double (cdecl *MYFUNC)(double, double, double&); // 函数原型 MYFUNC fun1 = NULL; // 函数别名 // fun1 = (MYFUNC)GetProcAddress(hDllInst,"_AddD"); // 函数名称 fun1 = (MYFUNC)GetProcAddress(hDllInst,"_AddDouble"); // 在DLL中声明的函数名 if(fun1) { // printf("%f\n",fun1(5.3)); printf("%f\n",fun1(1.1, 5.2, a)); printf("%f\n",a); } FreeLibrary(hDllInst); } return 0; }
Delphi代码(代码太多,只列举关键函数实现部分):
function _AddDouble(iVarA: Double; iVarB: Double; var iResult:Double):Double; cdecl; export; begin ShowMessage(FloatToStr(iVarA)); iResult:=iVarA+iVarB; result:=iResult; end; function _AddD(a: double): double; cdecl; begin result:=a+10.1; end;
另外,VC里可能默认使用cdecl方式。我没写传递方式就可以成功调用。
相关文章推荐
- #数字表示什么
- Delphi中的窗口子类化技术
- delphi7 不能运行提示'BORdbk70.dll'
- [转]多层数据库应用基于Delphi DataSnap方法调用的实现(三)对象池技术
- 多层数据库应用基于Delphi DataSnap方法调用的实现(四)BLOB字段的读写
- Delphi--最强大的开发工具(欢迎转载)
- delphi 常用函数
- 在Delphi的DBGrid中插入其他可视组件
- Delphi XE5 for android 图片缩放和拖动处理
- Delphi的format使用总结
- Delphi7 导出Dbgrid数据到Excel 默认路径设置为我的文档
- delphi xe 5 feature matrix
- DELPHI SHA1加密函数
- 谁说delphi没有IOCP库,delphi新的IOCP类库,开源中: DIOCP组件JSON流模块说明
- 谁说delphi没有IOCP库,delphi新的IOCP类库,开源中
- 回炉再煅——Delphi6,CxGrid4功能实现小记(分组、下拉框、多行复制)
- DELPHI 里面的迭代
- Delphi XE5教程10:Delphi字符集
- C# 调用 Delphi 动态库 和 Com 接口
- delphi 7 连接 MySql