Hardware ID Extractor
Examples of how to call function exported by the Hardware ID Extractor DLL
Source code examples
Managed programming languages
Unmanaged programming languages (DotNet)
Releasing the memory
VERY IMPORTANT! To make things easier, whenever you call a function that returns dynamic data (PAnsiChar 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 (using the Delphi DLL) need to call ReleaseMemory() after
calling ANY function that returns dynamic data (PAnsiChar strings).
If you don't do it, you will leak memory - about 8-32 bytes per function called. Visual Studio 2013 developers reported even a crash in ntdll.DLL
Example (pseudo code):
P= GetCpuID
ShowMessage('CPU ID is: '+ P)
ReleaseMemory(P)
C# example:
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr GetCPUID(ushort CoreMask);
[DllImport(DllPath, CallingConvention = CallingConvention.StdCall)]
private static extern void ReleaseMemory(IntPtr P);
{
IntPtr ptr = GetCPUID(CoreMask);
string cpuid = Marshal.PtrToStringAnsi(ptr); // convert to C# string
ReleaseMemory(ptr);
}
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 information 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 bullet
it means an ENTER has been inserted. Remove it to keep the code on a single line.
- Delphi programmers can use the HardwareIDExtractorPas.DLL. In this case the code will be just this: ShowMessage('CPU ID is: '+ GetCpuID)
- To see a list of exported functions click here.
- Additional resources for non-Delphi programmers - C++ equivalents for Delphi-specific types are available here.
|