C - Acessing Hardware ID Extractor DLL from C - SOLVED

The Hardware ID Extractor program extracts producer's data from your computer hardware (Hard drive, CPU, Physical memory).

C - Acessing Hardware ID Extractor DLL from C - SOLVED

Postby Viral » 04 Mar 2009, 05:18

Can you tell me how do i use the following functions in my C program.

function GetCPUID (CpuCore: byte): ShortString; stdcall;
function GetPartitionID(Partition : PChar): ShortString; stdcall;

I do the following and get error
Code: Select all
typedef char* (_stdcall *GETCPUID)(BYTE);
typedef char* (_stdcall *GETPID)(PCHAR);
GETCPUID pGetSerial;
GETPID pGetPID

HMODULE  hWtsLib = LoadLibrary("HardwareIDExtractor.dll");
if (hWtsLib){
pGetSerial = (GETCPUID)GetProcAddress(hWtsLib, "GetCPUID");
char *str = (char*) malloc(1024);
str = pGetSerial((BYTE)"1");

pGetPID= (GETPID )GetProcAddress(hWtsLib, "GetPartitionID");
char *str1 = (char*) malloc(1024);
str1 = pGetPID("C:");
}
Viral
 

Re: Acessing Hardware ID Extractor DLL from C

Postby admin » 04 Mar 2009, 12:00

On which line you get the error? Which is the error?

Also just a short note: ShortString has 255 characters in Pascal. One character is one byte.

Additional resources about importing DLL created in Pascal/Delphi to C/C++:
http://social.msdn.microsoft.com/Forums ... b929781c5/
http://msdn.microsoft.com/en-us/library/42b9ea93.aspx
http://www.experts-exchange.com/Program ... 64107.html
BioniX Wallpaper Changer makes you king over your desktop!
User avatar
admin
Site Admin
 
Posts: 829
Joined: 29 Nov 2007, 01:58

Re: Acessing Hardware ID Extractor DLL from C

Postby Viral » 05 Mar 2009, 02:47

My program crashes when i call the functions GetCPUID and GetPartitionID.
Can you tell me if the call is correct and that i am passing the correct arguments.
Viral
 

Re: Acessing Hardware ID Extractor DLL from C

Postby admin » 05 Mar 2009, 10:49

Viral wrote:My program crashes when i call the functions GetCPUID and GetPartitionID

I am not the specialist in C. I will ask somebody from our programming team. However, I am absolutely sure that he will ask me the exact error message you get, so I need this information in order to help you.
Th sooner I get this information, the sooner I can help you.

Please create an account on this forum. This way you will receive a message when a new answer is posted and you will not have to type the passwords every time you post.
BioniX Wallpaper Changer makes you king over your desktop!
User avatar
admin
Site Admin
 
Posts: 829
Joined: 29 Nov 2007, 01:58

Re: Acessing Hardware ID Extractor DLL from C

Postby TheHelper » 05 Mar 2009, 10:59

Hi Viral.

Try this way.

Code: Select all
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
}
TheHelper
 

Re: Acessing Hardware ID Extractor DLL from C

Postby Viral » 06 Mar 2009, 08:34

Thanks for the solution, the program does not crash anymore.

But now i get a message box saying Wrong CPU core.
Viral
 

Re: Acessing Hardware ID Extractor DLL from C

Postby admin » 06 Mar 2009, 11:52

Viral wrote:But now i get a message box saying Wrong CPU core.

How many cores does your CPU have?
BioniX Wallpaper Changer makes you king over your desktop!
User avatar
admin
Site Admin
 
Posts: 829
Joined: 29 Nov 2007, 01:58

Re: Acessing Hardware ID Extractor DLL from C

Postby Viral » 07 Mar 2009, 08:40

I tried 0,1,2,3 and none worked. My PC is a Intel Centrino dual processor.

Note: My partition ID is working now, so thanks for that.
Viral
 

Re: Acessing Hardware ID Extractor DLL from C

Postby admin » 07 Mar 2009, 12:13

Hi.
:)

The function is like this:

Code: Select all
function GetCPUID(CpuCore: byte): String;
begin
...
if (CpuCore<1) OR (CpuCore>2)
  then Mes('Wrong CPU core!')
  else  ...
...
end;

Where "Byte" is an unsigned 8 bits variable.

So, obviously the value that function receives is not 1 or 2. I think the way you declare the "CpuCore" variable or load a value in it is wrong.
BioniX Wallpaper Changer makes you king over your desktop!
User avatar
admin
Site Admin
 
Posts: 829
Joined: 29 Nov 2007, 01:58

Re: Acessing Hardware ID Extractor DLL from C

Postby Viral » 08 Mar 2009, 02:04

Thanks for the info, i tried few different ways and it worked for me.
Viral
 

Re: Acessing Hardware ID Extractor DLL from C

Postby admin » 08 Mar 2009, 02:10

Ok. Great.
:)
BioniX Wallpaper Changer makes you king over your desktop!
User avatar
admin
Site Admin
 
Posts: 829
Joined: 29 Nov 2007, 01:58


Return to Hardware ID Extractor