如何将这个 取硬盘硬序列 的函数封装为VB等编程语言可用的函数或控件。(50分)

  • 主题发起人 主题发起人 Pc 狂迷
  • 开始时间 开始时间
P

Pc 狂迷

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将这个 取硬盘硬序列 的函数装为VB等编程语言可用的函数或控件。这 DLL 在DELPHI
中可如下调用,可 VB 没有记录类型指针。我曾尝试写另一个 DLL 来调用它,并返回字串
但在 DELPHI 下会出现指针错,在VB下全线崩溃。希望大家帮我改改。(我是一个初学菜头
不要笑我。)
*************
* 调用示例子*
*************
unit Unit1;
interface

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

type DRIVER_INFO_OK = record
ModalNumber : array[0..39] of char;
SerialNumber : array [0..19] of char;
ControlNum : array[0..7]of char;
DriveType : dword;
Cylinders : dword;
Heads : dword;
Sectors : dword;
end;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function IsWinNT:boolean;
stdcall
external 'DiskID.dll'
name 'IsWinNT';{NT或9X平台判断}
function ReadPhysicalDrive(driveID:integer;buffer:Pointer;bufLen:integer):integer;
stdcall
external 'DiskID.dll'
name 'ReadPhysicalDriveInNT'
{NT 下 取硬盘硬序列函数}
function ReadPhysicalDrive9X(driveID:integer;buffer:Pointer;bufLen:integer):integer;
stdcall
external 'DiskID.dll'
name 'ReadDrivePortsInWin9X';{9X 下 取硬盘硬序列函数}
var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
x:DRIVER_INFO_OK;
intRet:integer;
begin
if IsWinNT then
ReadPhysicalDrive(0,@x,256)
else
ReadPhysicalDrive9X(0,@x,256);

Memo1.Lines.Add(x.SerialNumber)
{硬盘序列}
Memo1.Lines.Add(x.ModalNumber)
{硬盘型号}
Memo1.Lines.Add(x.ControlNum)
{忘了}
end;

end.
*********************************************************
* 我写的DLL,能返回正确结里,但是提示指针错误,请帮我改改*
*********************************************************
library PCDISKID;

uses
SysUtils,
Classes,
Windows;
type
DRIVER_INFO_OK = record
ModalNumber : array[0..39] of char;
SerialNumber : array [0..19] of char;
ControlNum : array[0..7]of char;
DriveType : dword;
Cylinders : dword;
Heads : dword;
Sectors : dword;
end;
function IsWinNT:boolean;
stdcall
external 'DiskID.dll'
name 'IsWinNT';
function ReadPhysicalDrive(driveID:integer;buffer:Pointer;bufLen:integer):integer;
stdcall
external 'DiskID.dll'
name 'ReadPhysicalDriveInNT';
function ReadPhysicalDrive9X(driveID:integer;buffer:Pointer;bufLen:integer):integer;
stdcall
external 'DiskID.dll'
name 'ReadDrivePortsInWin9X';

{$R *.res}

function Readdiskid:string stdcall;
var
x:DRIVER_INFO_OK;
begin
if IsWinNT then
ReadPhysicalDrive(0,@x,256)
else
ReadPhysicalDrive9X(0,@x,256);

Result := x.SerialNumber;

end;
exports
Readdiskid;
begin
end.
需要此 DLL 的,请留下 EMail
 
OK!zengxiaoxun@hotmail.com.
我试试封成DLL或是OCX,试试再给你.
 
接受答案了.
 
后退
顶部