Free desktop tools and utilities for Windows. Download our software now.Free desktop tools and utilities for Windows. Download our software now.
HomeContact
molecular biology software
scf trace assembly

Hardware ID Extractor
Hardware serial number extractor library

Delphi programming C/C++  programming VB (Visual Basic)  programming

 

 

 

 

How to use the DLL

 

 

 

 

Notes

  • In order to make the code examples below compatible with all language versions/strains and to keep it straight and to the object, the code has been simplified. Some snippets use visual controls to display the hardware ID numbers returned by the functions but the code for these visual controls (the forms) was not provided.
  • The code was formatted to fit this web page. Whenever you see a bulletit means an ENTER has been inserted. Remove it to keep the code on a single line.
  • VERY IMPORTANT NOTE: To make things easier, whenever you call a function that returns dynamic data (PChar strings), the DLL allocates a buffer and uses this buffer to pass the result back to you. In order to release this buffer all programmers except Delphi programmers need to call ReleaseMemory() after calling any function that returns dynamic data (PChar strings). If you don't do it, you will leak memory - about 8-32 bytes per function called.

 

 

 


 

 

 

 

Example for C Builder programmers

 

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
char* (__stdcall *GetIDESerialNumber)(BYTE);

HINSTANCE DllInst = NULL;



void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (DllInst == NULL) DllInst = LoadLibrary("HardwareIDExtractorC.dll");
  if (DllInst)
  {
    GetIDESerialNumber = (char* (__stdcall*)(BYTE))GetProcAddress(DllInst, "GetIDESerialNumber");

    //Now call the imported function
    Edit1->Text = GetIDESerialNumber(0);   // 0 = first IDE hard drive in your system 
  }
}


void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
  if ( DllInst ) FreeLibrary (DllInst);
}

 

 

 

Example in Visual Basic 5 programmers

In your BAS file write this: 

   Attribute VB_Name = "HardwareIDExtractor"
   Public Declare Function GetIDESerialNumber 
                                      Lib "HardwareIDExtractorC.dll.DLL" (ByVal DriveNumber As Byte) As String




In your FRM file write something like this:

   VERSION 5.00
   Begin VB.Form Form1
     Your form code here...
     bla bla bla...
   End


   Private Sub Command1_Click()
       Dim DriveNumber As Byte
       DriveNumber = 0
       Text1.Text = GetIDESerialNumber(DriveNumber)
   End Sub
 

 

 

Example in Visual FoxPro programmers

 

DECLARE STRING GetIDESerialNumber IN "HardwareIDExtractorC.dll" BYTE DriveNumber


Form1.Text1.Value = GetIDESerialNumber(0)
 

 

 

Example in C# (VS2005) programmers

 

namespace Project
{
    public partial class Form1 : Form
    { 
        [DllImport("HardwareIDExtractorC.dll")]
        public static extern String GetIDESerialNumber(byte DriveNumber);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = GetIDESerialNumber(0);
        }
    }
}

 

 

Example in VB.NET (VS2008) programmers

Imports System.Runtime.InteropServices
Public Class Form1

    Public Declare Function HardwareIDExtractorC 
                  Lib "HardwareIDExtractorC.dll" (ByVal DriveNumber As Boolean) As String
    

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        textBox1.Text = GetHardwareID(0)
    End Sub


    Public Sub New()
        InitializeComponent()
    End Sub


    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

End Class
 

 

 

Example in Delphi/Lazarus/Free Pascal programmers

The Hardware ID Extractor library was tested under Delphi 7, Delphi 2006 and Delphi 2007.

Interface

function CPUFamily: String; external 'HardwareIDExtractor.DLL';



Implementation

procedure Button1ClickExecute(Sender: TObject);
begin
  Label1.Caption:= CPUFamily;
end;
 

 

 

Example in VBA programmers

Private Declare Function HardwareIDExtractorC 
           Lib "HardwareIDExtractorC.dll" (ByVal DriveNumber As Byte) As String


Private Sub CommandButton1_Click()   
    TextBox1.Text = GetIDESerialNumber(0)
End Sub
 

 

 

 

Example in Liberty Basic programmers

open "HardwareIDExtractorC.dll" for dll as #id
calldll #id, "GetCpuIdNow", Pointer as uLong

function GetIDESerialNumber$(DriveNumber) 
         calldll #HwIDex, "GetIDESerialNumber", DriveNumber as ushort, pointer as ulong 
         GetIDESerialNumber$ = winstring(pointer) call ReleaseMemory pointer 
end function 
 

 Full example for Libery Basic users is available here.

 

 

 


 

 

Related links

 

Simple demo - Simple source code that shows how to use the DLL by writing only two lines of code.

Full demo - Source code of the 'Hardware ID Extractor.exe' application. Shows you how to use the DLL.

Additional resources for non-Delphi programmers - C++ equivalents for Delphi-specific types are available here.

 

 

 

 

free software
contig assembly software
unique hardware identifier  

Hardware ID Extractor DLL