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. com.octo.captcha.service.CaptchaServiceException: Invalid ID, could not validate unexisting o

    <p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px;"& ...

  2. 用JavaScript和CSS实现“在页面中水平和垂直居中”的时钟

    思路:实现起来最麻烦的事实上是水平居中和垂直居中,当中垂直居中是最麻烦的. 考虑到浏览器兼容性,网上看了一些资料,发如今页面中垂直居中确实没有什么太好的办法. 于是就採用了position:fixed ...

  3. NSArray NSMutableArray 初始化

    NSArray* Array;//此时数组没有初始化,数组=nil [Array objectAtIndex:2];//不会调用其属性方法,这里不会崩溃 NSMutableArray *Mutable ...

  4. erlang的Socket参数含义

    http://blog.csdn.net/pkutao/article/details/8572216 {ok, Listen} = gen_tcp:listen(?defPort, [binary, ...

  5. scala 判断对象相等/equals

    package scala_enhance.scalaextends import scala.collection.mutable.HashMap /** * scala中判断对象相等 * 原则: ...

  6. Display controller

    Field of the Invention The present invention relates to a display controller. Background to the inve ...

  7. 画廊视图(Gallery)的功能和用法

    Gallery与Spinner组件有共同的父类:AbsSpinner,表明Gallery和Spinner都是一个列表框.它们之间的区别在于Spinner显示的是一个垂直的列表选择框吗,而Gallery ...

  8. 《Java并发编程实战》第十二章 测试并发程序 读书笔记

    并发测试分为两类:安全性测试(无论错误的行为不会发生)而活性测试(会发生). 安全測试 - 通常採用測试不变性条件的形式,即推断某个类的行为是否与其它规范保持一致. 活跃性測试 - 包含进展測试和无进 ...

  9. win7 UAC bypass(微软已经给予了三组组件绕过UAC启动的特权)

    fireworm同学的翻译: 原文在http://www.pretentiousname.com/misc/win7_uac_whitelist2.html我只翻译了其中关于原理的一小部分,有兴趣的可 ...

  10. Linux经常使用的命令(两) - cd

    Linux cd 命令能够说是Linux中最主要的命令语句,其它的命令语句要进行操作,都是建立在使用 cd 命令上的.所以,学习Linux 经常使用命令.首先就要学好 cd 命令的用法技巧. 1. 命 ...