• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

delphi dll的两种调用方式示范代码

C# 水墨上仙 1398次浏览

delphi dll的两种调用方式演示代码
转自:http://blog.csdn.net/trassion/article/details/8439154

unit TestDLL_Pas;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Button2: TButton;
    Edit3: TEdit;
    Edit4: TEdit;
    CheckBox1: TCheckBox;
    Button3: TButton;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Button4: TButton;
    CheckBox2: TCheckBox;
    Button5: TButton;
    Button6: TButton;
    Edit9: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  _DLLMoudle: THandle;
//动态调用方式、先定义函数、后面在通过Button5Click过程调入个函数接口地址
  _GetPassWord:function (Pass:string):string;stdcall;
  _CheckPassWord:Function(SourcePass:string;EncryPass:string):boolean;stdcall;
  _StrEncrypt:Function(s: string; key: word): string;StdCall;
  _StrDecrypt:Function(s: string; key: word): string;StdCall;
  _GetRegistCode:Function(Pass:string):String;StdCall;
  _CheckRegistCode:Function(CompanyName,RegistCode:string):Boolean;StdCall;
//下面为静态调用方式
  function GetPassWord(Pass:string):ShortString;stdcall;external 'MyHRDLL.dll';
  function CheckPassWord(SourcePass,EncryPass:string):Boolean;stdcall;external 'MyHRDLL.dll';
  function StrEncrypt(s: string; key: word): ShortString;stdcall;external 'MyHRDLL.dll';
  function StrDecrypt(s: string; key: word): ShortString;stdcall;external 'MyHRDLL.dll';
  function GetRegistCode(Pass:string):ShortString;stdcall;external 'MyHRDLL.dll';
  function CheckRegistCode(CompanyName,RegistCode:string):Boolean;stdcall;external 'MyHRDLL.dll';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit2.Text := GetPassWord(Edit1.Text);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
  _bool :Boolean;
begin
  _Bool := CheckRegistCode(Edit3.Text,Edit4.Text);
  CheckBox1.Checked := _bool;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
  edit6.Text := GetRegistCode(edit5.Text);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
  CheckBox2.Checked := CheckPassWord(Edit7.Text,edit8.Text); 
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
   try
     _DLLMoudle := Loadlibrary('MyHRDLL.dll');
     ShowMessage('初始化成功!!!');
   except
     ShowMessage('初始化失败!!!');
     Exit;
   end;
   if _DLLMoudle > 32 then begin
      Try
        @_GetPassWord:=GetProcAddress(_DLLMoudle,'GetPassWord');              //打开串口
        @_CheckPassWord:=GetProcAddress(_DLLMoudle,'CheckPassWord');            //关闭串口
        @_StrEncrypt:=GetProcAddress(_DLLMoudle,'StrEncrypt');            //对卡号冲值
        @_StrDecrypt:=GetProcAddress(_DLLMoudle,'StrDecrypt');                //删除卡号
        @_GetRegistCode:=GetProcAddress(_DLLMoudle,'GetRegistCode');      //终端机清除刷卡记录
        @_CheckRegistCode:=GetProcAddress(_DLLMoudle,'CheckRegistCode');            //
        ShowMessage('DLL装载成功.............');
      Except
        ShowMessage('出错!!DLL打开失败!!不能做其他操作!!');
      End
   end;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
  edit9.Text :=  FormatDateTime('MMDDHHNN',Now);
end;
end.


喜欢 (0)
加载中……