Featured Posts

Subs Grabber Quick Fix New Subs Grabber quick fix has been released: Fixed: on podnapisi.net server search results are displayed, but download fails New: auto updater will now display what's new information when a new relaease/fix...

Readmore

Subs Grabber Quick Fix New Subs Grabber quick fix has been released: Fixed: on podnapisi.net server search results are displayed, but download fails New: auto updater will now display what's new information when a new relaease/fix...

Readmore

Subs Grabber (subtitle searching tool) v1.0.0 Launched Subs Grabber can be used to search for and download subtitles. It is using the database of the most popular subtitle websites and can find subtitles for movies and television series in various formats...

Readmore

USBPhysic (DLL Component) v1.0.0 Launched USBPhysic is a stand-alone component ( 32/64-bit Windows dynamic-link library - DLL ) that can be used to extract the physical vendor information from almost any USB (Universal Serial Bus) storage device....

Readmore

Hddphysic and Win Vista / 7 UAC (workaround) Issue:  Using Hddphysic to query hard drive physical data may fail sometimes on Vista / Windows 7 if UAC (User Account Control) is enabled and calling application is not launched with sufficient...

Readmore

  • Prev
  • Next

Hdd Physic Delphi Example (with source)

Posted on : 18-11-2009 | By : rlByte Team | In : HDDPhysic

0

 In order to get the hard disk serial number and other manufacturer information (NOT volume serial, only the unique one, the one that will not change after a format, physical one) using our hddphysic product and delphi code you need to do the following 3 easy steps:

(1) Create a new unit called HDDPhysic where you declare the imported hddphysic library functions :

HddPhysic.pas :

unit HddPhysic;

interface

  function Init (sUser: PAnsiChar; sRegCode: PAnsiChar): Integer; stdcall; external 'HDDPhysic.dll';
  function GetPhysicInfo (idiskIndex: Integer; iInfoType: Integer;  pHddInfo_OUT: PAnsiChar): Integer; stdcall; external 'HDDPhysic.dll';

implementation

end.

(2) Include the HddPhysic.pas in your project and then Call the Init function to initialize the user computer hard drives and get the total available devices

procedure TForm1.FormCreate(Sender: TObject);
var
 iWinDrive, iDrivesCount, i: Integer;
begin
   i:=0;
   //init HddPhysic dll
   iDrivesCount:=Init('<your reg id>','<your reg code>'); //add your registration data to unlock it

  if iDrivesCount>0 then
   begin
      //add drives indexes to combo
     Repeat
        ComboBoxDrives.Items.Add(IntToStr(i));
        Inc(i);
     Until i = iDrivesCount ;
      //get windows hdd drive index
      iWinDrive     := GetPhysicInfo(0, 6, nil);
      WinDrive.Text := IntToStr(iWinDrive);
      ComboBoxDrives.ItemIndex := iWinDrive ; //select windows drive index
   end;
end;

(3) Now that you have the total hard drives count you can query for the manufacturer information passing the disk index to the GetPhysicInfo function:

procedure TForm1.Button1Click(Sender: TObject);
var
  iDiskNo,iReturn: Integer;
  cInfo: AnsiString;
begin
  SetLength( cInfo, 512 ); //allocate some space in the buffer
  ClearEdit;
 
  iDiskNo:=ComboBoxDrives.ItemIndex; //get selected drive index
 
  iReturn    := GetPhysicInfo(iDiskNo,0,PAnsiChar(cInfo)); //0 = hdd serial number
  Edit1.Text := cInfo;                

  iReturn    := GetPhysicInfo(iDiskNo, 1, PAnsiChar(cInfo));    //1 = hdd model
  Edit2.Text := cInfo;
   
  iReturn    := GetPhysicInfo(iDiskNo, 2, PAnsiChar(cInfo));    //2 = hdd revision
  Edit3.Text := cInfo;

  iReturn    := GetPhysicInfo(iDiskNo, 3, PAnsiChar(cInfo));    //3 = hdd type
  Edit6.Text := cInfo;
       
  iReturn    := GetPhysicInfo(iDiskNo, 4, PAnsiChar(cInfo));    //4 = hdd size
  Edit5.Text := cInfo;
   
  iReturn    := GetPhysicInfo(iDiskNo, 5, PAnsiChar(cInfo));    //5 = hdd buffer size
  Edit4.Text := cInfo;

end;

Notes: No errors checks are done in this example, you should do some error checks. For example the Init function returns zero if no hdd are found, and GetPhysicInfo returns a lower than zero value if it fails for some reason.

  A complete project with source code example for using HDDPhysic component to get hard disk physical information with Delphi (CodeGear Delphi 2009) is available in the resources area of the product (here).

Write a comment