DELPHI封装dll的例子,留作纪念

    技术2022-05-20  66

    主程序

    unit Unit1;

    interface

    uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;

    type  TForm1 = class(TForm)    btn1: TButton;    procedure btn1Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end; function   ReturnCall(P:PChar):Boolean;stdcall;external   'test.dll ';var  Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.btn1Click(Sender: TObject);var    P:PChar;begin    try        P:=StrAlloc(1024);        if   ReturnCall(P)   then            ShowMessage(string(P));    finally        StrDispose(P);    end;end;

    end.

    ==========================

    DLL文件

    library test;

    uses  SysUtils,  Classes,  Forms,  Windows,  Messages,  Unit2 in 'Unit2.pas' {frmTest};

    {$R *.res}

    varfrmTest:TfrmTest;num:string;

     function   ReturnCall(P:PChar):Boolean;stdcall;    begin    with   TfrmTest.Create(nil)   do        try            ShowModal;            num:=edt1.Text;            StrCopy(P,PChar(num));            Result:=True;        finally            Free;        end;    end;

    exports ReturnCall;

    beginend.


    最新回复(0)