delphi调用C++写的Dll, 当然这个Dll要求是非MFC的Dll, 这样子才能被delphi调用. 根据C++定义函数的情况, Delphi有不同的相对应的处理方法.
1. 声明中不加__stdcall,采用VC默认格式__cdecl,但在Delphi中要注明调用格式为cdecl。
C++中例子:

  1. extern "C" int __declspec(dllexport) add(int x, int y);

Delphi中例子:

  1. function add(i:Integer; j:Integer):Integer; cdecl; External 'NonMfcDll.dll';

2. 声明中加上__stdcall
C++中例子:

  1. extern "C" int __declspec(dllexport) __stdcall stdadd(int x, int y);

因为加上__stdcall关键字, 会导致函数名分裂. 此时函数名变成_stdadd@8. 其中, 8是参数的总字节数
Delphi引用的方法1: 在delphi定义中加上"name'_stdadd@8'".

  1. function stdadd(i:Integer; j:Integer):Integer; stdcall; External 'NonMfcDll.dll' name'_stdadd@8';

Delphi引用的方法2: 增加def文件, 内容如下

  1. ; NonMfcDll.def : 声明 DLL 的模块参数。
  2. LIBRARY      "NonMfcDll"
  3. EXPORTS
  4. ; 此处可以是显式导出
  5. stdadd @1

delphi的定义如下

  1. function add(i:Integer; j:Integer):Integer; stdcall; External 'NonMfcDll.dll';

http://blog.csdn.net/huang_xw/article/details/7524359

Delphi 调用C/C++的Dll(stdcall关键字, 会导致函数名分裂. 此时函数名变成_stdadd@8)的更多相关文章

  1. 发现个delphi调用vc写的Dll中包括pchar參数报错奇怪现象

    发现个delphi调用vc写的Dll中包括pchar參数奇怪现象 procedure中的第一行语句不能直接调用DLL的函数,否则会执行报错,在之前随意加上条语句就不报错了奇怪! vc的DLL源代码地址 ...

  2. Delphi调用C++写的dll示例

    最近做一个读市民卡的项目,读卡器公司提供的读市民卡dll是用C++写的. 下面记录一些自己的心得,供需要的朋友参考. 声明dll函数要加上stdcall关键字,否则可能会报地址非法的错误. 代码: u ...

  3. Delphi 调用C# 编写的DLL方法

    近来,因工作需要,必须解决Delphi写的主程序调用C#写的dll的问题.在网上一番搜索,又经过种种试验,最终证明有以下两种方法可行:    编写C#dll的方法都一样,首先在vs2005中创建一个“ ...

  4. Delphi调用c++写的dll (me)

    unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...

  5. Delphi 调用C# DLL(包含委托)

    例子 C# Dll: using System; using System.Collections.Generic; using System.Text; using System.Diagnosti ...

  6. c++builder delphi 调用dll dll编写

    c++builder动态调用dll // 定义 typedef int __stdcall MyFunction (int x, char *str); ; String dllName = &quo ...

  7. CommMonitor8.0 串口过滤驱动 SDK DLL版本 C#/Delphi调用DEMO

    CommMonitor8.0 SDK DLL 版本,此版本是直接调用DLL. Delphi调用定义: constCommMOnitor8x = ‘CommMOnitor8x.dll’; typeTOn ...

  8. .net DLL 注册 regasm delphi调用

    .net DLL 注册 regasm regasm regasm myTest.dll regasm.exe 打开vs2005自带的工具“Visual Studio 2005命令提示”,输入上述命令 ...

  9. Delphi调用C# 编写dll动态库

    Delphi调用C# 编写dll动态库 编写C#dll的方法都一样,首先在vs2005中创建一个“类库”项目WZPayDll, using System.Runtime.InteropServices ...

随机推荐

  1. Android UI:看看Google官方自定义带旋转动画的ImageView-----RotateImageView怎么写(附 图片淡入淡...)

    众所周知,想要让ImageView旋转的话,可以用setRotation()让其围绕中心点旋转,但这个旋转是不带动画的,也就是旋转屏幕时图片噌的一下就转过去了,看不到旋转的过程,此UI体验不大好,为此 ...

  2. [Vue] Use basic event handling in Vue

    Let's use a range of events and their modifiers to look at the cool ways we can deal with event hand ...

  3. 线程基础:JDK1.5+(9)——线程新特性(中)

    (接上文<线程基础:JDK1.5+(8)--线程新特性(上)>) 3.工作在多线程环境下的"计数器": 从这个小节開始,我们将以一个"赛跑"的样例. ...

  4. 【hdu 2897】邂逅明下

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  5. Hudson版本控制 (备注)

    http://www.ttlsa.com/tools/install-hudson-on-linux/

  6. ospf基本配置协议

     OSPF(开放最短路径优先)协议是链路状态路由协议类.对于 IPv4 的 OSPF 当前版本号 OSPFv2,的版本号 John Moy 在 RFC 1247 中引入,并在 RFC 2328 中 ...

  7. CocoaPods停在Analyzing dependencies的解决方案

    解决办法: 1: 换镜像索引库 国内有人建立了cocoapods的索引库镜像,可以通过如下命令更改镜像: pod repo remove master  pod repo add master htt ...

  8. Linux环境编写脚本安装配置JDK,Tomcat,含Tomcat自启动

    mkdir /usr/java mkdir /znywImage cp -f /usr/jdk-7u79-linux-x64.tar.gz /usr/java tomcatPath=/usr/apac ...

  9. 【9210】找礼物(char* num[2000]的使用 get char num[i] = new char[1000])

    Time Limit: 10 second Memory Limit: 2 MB 问题描述 新年到了,突然间,就在那美丽的一霎那,你好友和你(K个人)的周围满是礼物,你发扬你帅气的风格,让你的好友先拿 ...

  10. javascript数据结构与算法 零(前记+前言)

    前记 这本书Data Structure and Algorithm with Javascript 我将其翻译成<< javascript 数据结构和算法>> 为什么这么翻译 ...