DiskID32演示实例源码(附工程文件)
看到有兄弟问这个DLL的用法,按照说明编写了个。DLL调用可以动态调用和静态调用,程序里都写了。unit Unit1;
inte**ce
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type mychar=array of char;
type TDiskID32=Function(var DiskModel,DiskID:mychar):BOOL;stdcall;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function DiskID32(var DiskModel,DiskID:mychar):BOOL;stdcall;external './DiskId32.dll' name 'DiskID32';
procedure TForm1.Button1Click(Sender: TObject);
var
f:TDiskID32;
lib:THandle;
diskmodel,diskid:mychar;
begin
//动态调用
lib:=0;
try
lib:=LoadLibrary(PChar('.\Diskid32.dll'));
f:=GetProcAddress(lib,PChar('DiskID32'));
f(diskmodel,diskid);
memo1.Lines.add('动态调用');
memo1.Lines.Add(diskmodel);
memo1.Lines.add(diskid);
finally
FreeLibrary(lib);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
diskmodel,diskid:mychar;
begin
//静态调用
DiskID32(diskmodel,diskid);
memo1.Lines.add('静态调用');
memo1.Lines.Add(diskmodel);
memo1.Lines.add(diskid);
end;
end.
[ 本帖最后由 caterpilla 于 2008-8-5 09:07 编辑 ] 东西不错!!/:good
页:
[1]