library dd;

{ 使用字符串参数或嵌套字符串参数需要在uses子句中包括sharemm单元,并将BorlandMM.dll与您的应用程序一起发布。
否则需要对参数值使用PChar或ShortString类型。 } uses
SysUtils,
Classes,
Dialogs; {$R *.res} // 计算字符串长度,默认使用了Delphi的寄存器调用规范,第一个参数存储字EAX中。EAX表示了指向字符串的指针。
//
Delphi自动进行字符串管理,并在字符串文字的第一个位置之前包含了一些额外的数据。
Function MyLength(const S: String): Integer;
asm
mov ecx, [eax-] // 读出字符串起始地址向下偏移4个字节处的32比特值。
mov result, ecx
end; Procedure HelloFromServerLand;
begin
ShowMessage('Hello from server land');
end; exports
HelloFromServerLand,
MyLength;
begin end.

//

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm}

// 导出这些函数,函数名和参数都不能少。但就这么简单!
procedure HelloFromServerLand; external 'dd.dll';
Function MyLength(const S: String): Integer; external 'dd.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
HelloFromserverLand;
end; procedure TForm1.Button2Click(Sender: TObject);
var
S: String;
n: Integer;
begin
s:='Delphi';
n:=MyLength(s);
ShowMessage(IntToStr(n));
end; end.

参考:

http://blog.csdn.net/lailai186/article/details/9144023
http://blog.csdn.net/lailai186/article/details/8770643
http://blog.csdn.net/lailai186/article/details/8763334
http://blog.csdn.net/lailai186/article/details/8770487
http://blog.csdn.net/suiyunonghen/article/details/2207649

1 参数类型最好与window C++的参数类型一致。不要用DELPHI的数据类型。
2 最好有返回值[即使是一个过程],来报出调用成功或失败,或状态。成功或失败的返回值最好为1[成功]或0[失败].一句话,与windows c++兼容。
3 用stdcall声明后缀。
4 最好大小写敏感。
5 无须用far调用后缀,那只是为了与windows 16位程序兼容。
http://secyaher.blog.163.com/blog/static/389557720121245724109/?suggestedreading&wumii

我的第一个Delphi DLL的更多相关文章

  1. Visual Studio 调用 Delphi DLL 会退出的解决方案

    新写了一个 Delphi 的 dll 供 C# 程序调用,却发现在使用 Visual Studio 2012 进行调试时,程序会在调用后自动退出. 经过对比,只需要将工程属性中“调试”一页下的“启用 ...

  2. Delphi Dll 动态调用例子(3)-仔细看一下

    http://blog.163.com/bxf_0011/blog/static/35420330200952075114318/ Delphi 动态链接库的动态和静态调用 为了让人能快速的理解 静态 ...

  3. vb6如何调用delphi DLL中的函数并返回字符串?

    1,问题描述 最近发现vb6调用delphi DLL中的函数并返回字符串时出现问题,有时正常,有时出现?号,有时干脆导致VB程序退出 -- :: 将金额数字转化为可读的语音文字:1转化为1元 ???? ...

  4. delphi dll调用问题

    dll传递string实现方法 delphi中dll传递string的实现方法: dll项目uses第一个引用sharemem单元; 调用的项目uses第一个引用sharemem单元; 调用的单元us ...

  5. delphi dll创建及调用

    第一章 DLL简单介绍由于在目前的学习工作中,需要用到DLL文件,就学习了下,在这里作个总结.首先装简单介绍下DLL:1,减小可执行文件的大小DLL技术的产生有很大一部分原因是为了减小可执行文件的大小 ...

  6. 在.net中调用Delphi dll的Pchar转换

    Pchar是非托管代码,要在.net中调用Delphi dll中的功能,请使用MarshalAs属性告知.net调用PInvoke去转换.net中标准的string类型.如果Delphi dll是De ...

  7. 创建一个动态链接库 (DLL),使用VS2010

    在本演练中,您将创建一个动态链接库 (DLL),其中包含可供其他应用程序使用的有用例程.使用 DLL 是一种重用代码的绝佳方式.您不必在自己创建的每个程序中重新实现这些例程,而只需对这些例程编写一次, ...

  8. C# 调用Delphi dll

    delphi dll 源码: library dllres; type char10 = ..] of char; TMydata = packed record id: Integer; name: ...

  9. Borland.Delphi.dll

    Borland.Delphi.dll Borland Delphi Runtime for .NET Imports Borland.DelphiImports Borland.Delphi.Unit ...

随机推荐

  1. linux-awk-3

    awk 基础语法 Awk –Fs '/pattern/ {action}' input-file (或者) Awk –Fs '{action}' input-file -F 为字段分界符.如果不指定, ...

  2. 介绍HTML5几种存储方式

    总体情况 h5之前,存储主要是用cookies.cookies缺点有在请求头上带着数据,大小是4k之内.主Domain污染. 主要应用:购物车.客户登录 对于IE浏览器有UserData,大小是64k ...

  3. MoreExecutors工具类使用

    MoreExecutors是guava提供的工具类,是对jdk自带的Executors工具类的扩展,主要方法如下: 1.addDelayedShutDown()方法的两个重载: public stat ...

  4. std::string 和 CString问题

    std::string stdTemp; CString strTemp; strTemp = stdTemp;    ;//这一步直接赋值可不可以 因为CString可以接受const char*的 ...

  5. k8s的node节点,执行kubectl get XXX报错

    报错现象: [root@localhost ~]# kubectl get nodes The connection to the server localhost:8080 was refused ...

  6. max pool实现

    题目 二维矩阵(nm) 求每个(lw)的子矩阵的最大元素, 就是一维滑动窗口的升级版 自己瞎掰的题解 #include <bits/stdc++.h> using namespace st ...

  7. 微信小程序登录 code 40029 天坑

    微信登录时 code 大坑(服务端返回如下代码) {"errcode":40029,"errmsg":"invalid code, hints: [ ...

  8. Selenium 三种等待方式详解

    我们在做WEB自动化时,一般要等待页面元素加载完成后,才能执行操作,否则会报找不到元素的错误,这样就要求我们在有些场景下加等待时间. 我们平常用到的有三种等待方式: 强制等待 隐式等待 显示等待 一. ...

  9. 3-Gitblit服务器搭建及IDEA整合Git使用

    背景:虽然有GitHub.GitLab这样强大的Git仓库,但是涉及私有Git库要收费,所以自己动手搭建免费的用用 环境:windows 7 旗舰版.JDK 1.8.IDEA 2017 ------- ...

  10. android图片的缩放、圆角处理

    android中图片缩放方法有三种:1,bitmapFactory:2,bitmap+metrix:3,thumbUtil 方法一:bitmapFactory: public static Bitma ...