zoukankan      html  css  js  c++  java
  • 我的第一个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

  • 相关阅读:
    sitemap.xml
    Java--调试--单步调试,断言,单元测试
    同时显示多个 Notification
    HttpURLConnection请求数据流的写入(write)和读取(read)
    Spring jdbc 对象Mapper的简单封装
    mongodb之java CRUD 简单操作
    第三章 AOP 基于@AspectJ的AOP
    从源码角度深入分析log4j配置文件使用
    log4j.properties文件配置--官方文档
    JS问题Uncaught ReferenceError:XXXX is not defined
  • 原文地址:https://www.cnblogs.com/findumars/p/3254350.html
Copyright © 2011-2022 走看看