• 我的第一个Delphi DLL


    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

  • 相关阅读:
    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第13章节--使用业务连接服务创建业务线解决方式 创建启用BCS的业务解决方式
    POI 导入excel数据自己主动封装成model对象--代码分析
    四旋翼飞行器Quadrotor飞控之 PID调节(參考APM程序)
    Detours改动段属性漏洞
    C++中父类的虚函数必需要实现吗?
    深入理解JavaScript系列(12):变量对象(Variable Object)
    CSS 类、伪类和伪元素差别具体解释
    Qt Quick 之 PathView 具体解释
    读《一年一度屈原祭,端午时节话公知》有感
    Volley简单学习使用五—— 源代码分析三
  • 原文地址:https://www.cnblogs.com/findumars/p/3254350.html
Copyright © 2020-2023  润新知