• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

我的第一个DelphiDLL

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
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] // 读出字符串起始地址向下偏移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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Matlab调用其他文件夹下的函数发布时间:2022-07-18
下一篇:
matlab学习笔记7-定时器发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap