Jump to content

DllCall help please.


Illuma
 Share

Go to solution Solved by Sundance,

Recommended Posts

Hi, I am struggling to get a function in a .dll file to work, I have had a good look about here & I have looked at similar functions and how they are called in other peoples working scrips (Martins CommMG), no matter what I try I cant get this .dll to return any information. The .dll allows you to return specific information / serial numbers from the PC, I want to use it so I can keep specific information on PC's in a file for my own records, It would be useful here to people if they wish to lock software to a certain PC. If anyone can please help me return some useful data from the .dll I think I could workout how to get the rest.

Here is a list of functions for the .dll

 

Functions exported by this DLL:

===============================================================================

UNIT
CubicHardID
Version 1.4a

COPYRIGHT
CubicDesign 2012
All rights reserved
www.Soft.Tahionic.com

Programming languages supported:
C, C++, VB, FoxPro, VBA, .Net, etc
Delphi programmers click this

================================================================================



CONSTANTS

// OSMemType
MemoryLoad = 1; // Total memory used in percents (%)
TotalPhys = 2; // Total physical memory in bytes
AvailPhys = 3; // Available physical memory (bytes)
TotalPageFile = 4; // Total page file in (bytes)
AvailPageFile = 5; // Available page file (bytes)
TotalVirtual = 6; // Total virtual memory in bytes
AvailVirtual = 7; // Available virtual memory (bytes)

// ProcMemType
WorkingSetSize =1; //- the current working set size, in bytes.
PageFaultCount =2; //- the number of page faults.
PeakWorkingSetSize =3; //- the peak working set size, in bytes.
QuotaPeakPagedPoolUsage =4; //- The peak paged pool usage, in bytes.
QuotaPagedPoolUsage =5; //- The current paged pool usage, in bytes.
QuotaPeakNonPagedPoolUsg =6; //- The peak nonpaged pool usage, in bytes.
QuotaNonPagedPoolUsg =7; //- The current nonpaged pool usage, in bytes.
PagefileUsage =8; //- The current space allocated for the pagefile, in bytes. Those pages may or may not be in memory.
PeakPagefileUsage =9; //- The peak space allocated for the pagefile, in bytes.


// CPU
function GetCPUSpeed : Double;
function CPUFamily : String; // Get cpu identifier from the windows registry
function GetCpuTheoreticSpeed: int; // Get cpu speed (in MHz)
function IsCPUIDAvailable : Boolean;
function GetCPUID (CoreMask: Word): String; // Get the ID of the specified logical CPU. For CoreMask parameter see this page.
function GetCpuIdNow : String; // Get the ID of the first available logical CPU
function GetCPUCount : int; // The number of LOGICAL processors in the current group
function IsIntel64BitCPU : Boolean; // Detects IA64 processors
function GetCPUVendor : String; // New GetCPUVendor function. Reported to work with D7 and D2009.

// RAM
function MemStatWindows (OSMemType : Byte): LongInt; // in Bytes. Limited by the capacity of the OS (32bits OSs will report max 2GB)
function MemStatWindows_KB (OSMemType : Byte): String; // in KB
function MemStatWindows_MB (OSMemType : Byte): String; // in MB
function MemStatCurrProc (ProcMemType: Byte= 1): LongInt; // Returns data about the memory used of the current process
function MemStatPeak: LongInt; // Peak memory used by current program

// RAM - Advanced stuff
function GetPageSize: LongInt; // The page size and the granularity of page protection and commitment. This is the page size used by the VirtualAlloc function.
function GetMemGranularity: int; // Granularity with which virtual memory is allocated (in KB)
function GetLowAddr: LongInt; // Lowest RAM memory address accessible to applications (this is the RAM address, not virtual memory address)
function GetHiAddr: LongInt; // Lowest RAM memory address accessible to applications

// HDD
function GetPartitionID (Partition : string): String; // Get the ID of the specified patition. Example of parameter: 'C:'
function GetIDESerialNumber(DriveNumber: Byte): String; // Get the unique ID of the harddrive. DriveNumber parameters can have values from 0 to 7. Number 0 corresponds to the first physic drive. UAC details

// BIOS (NEW!)
function BiosDate: string;
function BiosVersion: string; // Could be something like: TOSQCI - 6040000 Ver 1.00PARTTBL. TOS is comming from Toshiba Q is comming from product series (Qosmio)
function BiosProductID: string; // Manufacturer product (laptop, PC) ID - Could be something like: Toshiba_PQX33U-01G00H
function BiosVideo: string;

// Utils
function BinToInt(Value: String): int;
function CoreNumber2CoreMask(CoreNo: int): int; // Details
function GetDllVersion: Double;
function GetDllVersion: Double;

Note:
All strings used in this DLL are LPSTR (PAnsiChar). Byte is 'unsigned char'.
The following functions are freely accessible (you don't need a to purchase the DLL in order to use them): ChangeByteOrder, IntToBin, CoreNumber2CoreMask, WindowsProductID, GetPageSize, GetMemGranularity, GetLowAddr, GetHiAddr, MemStatWindows, MemStatWindows_KB, MemStatWindows_MB, MemStatCurrProc, MemStatPeak, IsCPUIDAvailable, GetCpuTheoreticSpeed, GetCPUCount, IsIntel64BitCPU, GetDllVersion, ReleaseMemory
 

 

Here are some examples of code usage

 

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

Interface

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



Implementation

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


Demo application:
Source code (basic demo)
Source code (full demo)





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

 

The .dll file is available in a Delphi version, I chose the universal version (not sure if that was correct) however I have tried both and they both returned the same value which is incorrect.

I am trying to get the unique serial number of the hard drive, my example returns 0 when run, if I remove the (0) at the end of my GetIDESerialNumber(0) I get an info box that quotes "invalid drive!" so I think something is working? Here is the code I am running now:-

Local $resultHDDSN
Local $dll = DllOpen("HardwareIDExtractorC.dll")


$resultHDDSN = DllCall('HardwareIDExtractorC.dll', 'str', 'GetIDESerialNumber(0)')


ConsoleWrite('+_WinAPI_GetLastErrorMessage() = ' & _WinAPI_GetLastErrorMessage())
ConsoleWrite('+_WinAPI_GetLastError() = ' & _WinAPI_GetLastError() & @crlf)
If @error Then Exit


MsgBox(262144, "IDE drive 0 Serial Number", $resultHDDSN )

DllClose($dll)

I have attached the .dll file I am using. Any help is greatly appreciated.

 

HardwareIDExtractorC.zip

Link to comment
Share on other sites

  • Solution

Hi.

You must use $resultHDDSN[0] as the result of a successfull DLL call...

#include <winapi.au3>

Local $resultHDDSN
Local $dll = DllOpen("HardwareIDExtractorC.dll")
ConsoleWrite("DllOpen with result: " & $dll & @CRLF)

$resultHDDSN = DllCall('HardwareIDExtractorC.dll', 'str', 'GetIDESerialNumber', "BYTE", 0)

ConsoleWrite("DllCall  @error: " & @error & @CRLF)

ConsoleWrite('+_WinAPI_GetLastErrorMessage() = ' & _WinAPI_GetLastErrorMessage())
ConsoleWrite('+_WinAPI_GetLastError() = ' & _WinAPI_GetLastError() & @crlf)
If @error Then Exit

ConsoleWrite("resultHDDSN =" & $resultHDDSN[0] & @CRLF)

DllClose($dll)
Edited by Sundance
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...