- UID
- 13801
注册时间2006-5-22
阅读权限40
最后登录1970-1-1
独步武林
该用户从未签到
|
看到有兄弟问这个DLL的用法,按照说明编写了个。DLL调用可以动态调用和静态调用,程序里都写了。
unit Unit1;
inte**ce
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type mychar=array[0..31] 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 编辑 ] |
-
-
diskid.rar
206.8 KB, 下载次数: 5, 下载积分: 飘云币 -2 枚
diskid32演示实例
|