Delphi can import HardwareID.dll functions with external declarations. This example uses stdcall and a caller-allocated buffer, which works in both 32-bit and 64-bit builds.

The sample also shows how to check the DLL version and detect VMware.

Before you start

  1. Install the HardwareID DLL trial.
  2. Add the external declarations to a unit.
  3. Call SetLicenseKey() during startup.
  4. Read the ID into a buffer and use it in your registration flow.

Complete example

Delphi
const
  DLLFile = '.\HardwareID.DLL';

var
  Form1: TForm1;

procedure SetLicenseKey(Regcode: PAnsiChar); stdcall; external DLLFile;
procedure SetAppName(AppName: PAnsiChar); stdcall; external DLLFile;
function GetHardwareId(HDD, NIC, CPU, BIOS: LongBool; lpHWID: PAnsiChar; nMaxCount: Integer): Integer; stdcall; external DLLFile;
function GetDllVer(lpVersion: PAnsiChar; nMaxCount: Integer): Integer; stdcall; external DLLFile;
function IsInsideVMWare(): Integer; stdcall; external DLLFile;
function IsInsideVirtualPC(): Integer; stdcall; external DLLFile;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  sVer: array[0..254] of AnsiChar;
begin
  GetDllVer(sVer, SizeOf(sVer));

  Self.Caption:= Format('AzSDK HardwareId DLL [%s] DEMO', [sVer]);

  SetLicenseKey('Your-License-Key');

  if IsInsideVMWare = 1 then
    labIsVMware.Caption:= 'Yes';

  if IsInsideVirtualPC = 1 then
    labIsVirtualPC.Caption:= 'Yes';
end;

procedure TForm1.btnGetClick(Sender: TObject);
var
  sHWID: array[0..254] of AnsiChar;
  iRtn: Integer;
begin
  SetAppName('');

  iRtn:= GetHardwareId(cbHDD.Checked, cbNIC.Checked, cbCPU.Checked, cbBIOS.Checked, sHWID, SizeOf(sHWID));
  if iRtn > 0 then
    Edit0.Text := sHWID;
end;

procedure TForm1.btnGetWithAppClick(Sender: TObject);
var
  sHWID: array[0..254] of AnsiChar;
  iRtn: Integer;
  sAppName: String;
begin
  //Set your application name
  sAppName:= Edit1.Text;
  SetAppName(PAnsiChar(sAppName));

  iRtn:= GetHardwareId(cbHDD.Checked, cbNIC.Checked, cbCPU.Checked, cbBIOS.Checked, sHWID, SizeOf(sHWID));
  if iRtn > 0 then
    Edit2.Text := sHWID;
end;

How it works

  • The DLL must be on the search path or in the application directory.
  • All functions use the stdcall calling convention.
  • Keep the license key out of source control where possible.
During evaluation, leave the placeholder license key in place. After purchase, replace it with the key from your email.