2017年9月7日 星期四

[範例]DLL編寫與呼叫

DLL project

library Dll_procedure;

uses
  SysUtils, Classes,
  Windows, ExtCtrls;

{$R *.res}


function fn_StrToInt(sValue:String):Integer; stdcall;
begin
  Result := StrToInt(sValue);
end;

exports fn_StrToInt;

begin
end.

----------------------------------------------------
Text Project - Call Dll

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

function fn_StrToInt(sValue:String):Integer; stdcall; External 'Dll_procedure.dll';

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var sStr:String;
  i:Integer;
begin
  sStr := '123';
  i := fn_StrToInt(sStr);
  sStr := IntToStr(i);
  showmessage(sStr);
end;


end.

沒有留言:

張貼留言