delphi动态调用dll

unit Unit1;

interface

uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type

  TForm1 = class(TForm)

    Edit1: TEdit;

    Label1: TLabel;

    Button1: TButton;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

  SendPatientInfo = procedure(sParam:ansistring); stdcall;//无回参用procedure,有回参用function,我也不知道为什么

var

  Form1: TForm1;

implementation

{$R *.dfm}

var

  FDLL130Handle: THandle;

  DLL130Name: string = 'D:\demo\delphi\Metabolism.dll';

  bStop: boolean;

procedure TForm1.Button1Click(Sender: TObject);

var

  sendPInf:SendPatientInfo;

begin

  FDLL130Handle := Loadlibrary(Pchar(DLL130Name));

  if FDLL130Handle = 0 then

  begin

    ShowMessage(DLL130Name+'不存在');

  Exit;

  end;

  @sendPInf := GetProcAddress(FDLL130Handle, 'SendPatientInfo');

  if @sendPInf = nil then

  begin

    ShowMessage('SendPatientInfo 函数无法获得!');

  end else

  begin

    sendPInf(pchar(Edit1.Text));

  end;

end;

end.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容