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. 详解springmvc控制登录用户session失效后跳转登录页面

    springmvc控制登录用户session失效后跳转登录页面,废话不多少了,具体如下: 第一步,配置 web.xml <session-config> <session-timeo ...

  2. linux 系统升级中的一些配置

    1. 关闭IPV6 vi /etc/sysconfig/network NETWORKING_IPV6=no    #掉 source /etc/sysconfig/network vi /etc/m ...

  3. [Angular] NgRx/effect, why to use it?

    See the current implementaion of code, we have a smart component, and inside the smart component we ...

  4. Install .NET Core SDK on Linux CentOS / Oracle x64 | .NET

    原文:Install .NET Core SDK on Linux CentOS / Oracle x64 | .NET Linux发行版  CentOS / Oracle添加dotnet产品Feed ...

  5. SpringMVC3,使用RequestMappint的Param参数,实现一个url绑定多个方法

    SpringMVC中,默认不能把多个相同的url绑定到同一个方法.如果需要绑定,需要增加param参数,而且值要不同. 我自己没有这个需求,或者就是有需求,我也想到的是使用不同的url. 项目中有少部 ...

  6. App各种Icon及Launch image的尺寸和用途

    App各种Icon及Launch image的尺寸和用途 IOS7,8 Asset iPhone 6 Plus (@3x) iPhone 6 and iPhone 5 (@2x) iPhone 4s ...

  7. SpringBoot JPA 专题

    Error: Error starting ApplicationContext. To display the auto-configuration report re-run your appli ...

  8. JAVA从本机获取IP地址

    JAVA从本机获取IP地址 论述: 此篇博客是在工作的时候,需要获得当前网络下面正确的ip地址,在网上查阅很多博客,网上一个比较普遍的说法是通过InetAddress.getLocalHost().g ...

  9. git安装使用详解

    Git是分布式版本控制系统,那么它就没有中央服务器的,每个人的电脑就是一个完整的版本库,这样,工作的时候就不 需要联网了,因为版本都是在自己的电脑上.既然每个人的电脑都有一个完整的版本库,那多个人如何 ...

  10. jQuery Mobile移动开发

    1.在<head>元素中包括JavaScript文件是传统的方法.然而,依据Yahoo!"80%的终于用户响应时间在前端上"的说法,这些事件大部分花在资产的下载上,比如 ...