Visual C
typedef struct ShortString { char len; char data[255]; }; typedef void (_stdcall *GETCPUID)(struct ShortString *result, BYTE cpuCore);
GETCPUID pGetSerial;
HMODULE hWtsLib = LoadLibrary("HardwareIDExtractor.dll"); if (hWtsLib) { ShortString serial; pGetSerial = (GETCPUID)GetProcAddress(hWtsLib, "GetCPUID"); pGetSerial(&serial, '1'); char *str = malloc(serial.len + 1); // include space for the trailing \0 strlcpy(str, serial.data, serial.len); str[serial.len] = '\0'; // drop in the trailing null }
DotNet C#
[DllImport("the_name_of_the_delphi_library.dll")] public static extern string CPUFamily();
[DllImport("the_name_of_the_delphi_library.dll")] public static extern int GetCpuTheoreticSpeed();
[DllImport("the_name_of_the_delphi_library.dll")] public static extern bool IsCPUIDAvailable();
[DllImport("the_name_of_the_delphi_library.dll")] public static extern string GetCPUID(byte cpuCore);
[DllImport("the_name_of_the_delphi_library.dll")] public static extern string GetCPUVendor();
[DllImport("the_name_of_the_delphi_library.dll")] public static extern uint MemoryStatus(int memType);
[DllImport("the_name_of_the_delphi_library.dll")] public static extern string MemoryStatus_MB(int memType);
[DllImport("the_name_of_the_delphi_library.dll")] public static extern string GetPartitionID(char partition);
[DllImport("the_name_of_the_delphi_library.dll")] public static extern string GetIDESerialNumber(byte driveNumber);
class Program { [DllImport("the_name_of_the_delphi_library.dll")] public static extern double GetCPUSpeed();
static void Main(string[] args) { double cpuSpeed = GetCPUSpeed(); Console.WriteLine("CPU speed: {0}", cpuSpeed); } }
Delphi
In the Interface section of your unit declare the function you want to import. For example, to show your CPU type/family, use:
function CPUFamily : ShortString; stdcall; external 'HardwareIDExtractor.DLL';
Then, in the 'Implementation section call that function. Like this:
Label1.Caption:= CPUFamily;
Full demo source code is availalbe here.
Note: Please remember that we are Delphi developers. The information provided for other programming languages except Delphi may not be accurate.
Related words: Get disk serial, real hard drive serial number, hardware ID number, programming code, DLL library, extract hardware info, get CPU producer frequency and producer
|