Jump to content

Recommended Posts

Posted (edited)

Hey there, i think i am doing something wrong... I want to call some Functions in a DLL API File:

 

#include <MsgBoxConstants.au3>

Global $hDll, $aResult, $aResult2

Local $tGetAPIVersion=DllStructCreate("char apiVersion[200]") ;this one is working
Local $tSearchDevice=DllStructCreate("int numDevicesFound;int* deviceIDS;char** deviceSerial;char** deviceType");this is not working


$hDll = DllOpen("RSA_API.dll")
If $hDll <> -1 Then
        $aResult = DllCall($hDll, "none:cdecl", "DEVICE_GetAPIVersion", "ptr", DllStructGetPtr($tGetAPIVersion))
        $aResult2 = DllCall($hDll, "none:cdecl", "DEVICE_Search", "ptr", DllStructGetPtr($tSearchDevice))
        If Not @error Then
            MsgBox(0,"ApiVersion:",DllStructGetData($tGetAPIVersion,"apiVersion"))
            MsgBox(0,"numDevicesFound:",DllStructGetData($tSearchDevice,"numDevicesFound"))
            MsgBox(0,"deviceIDS:",DllStructGetData($tSearchDevice,"deviceIDS"))
            MsgBox(0,"deviceSerial:",DllStructGetData($tSearchDevice,"deviceSerial"))
            MsgBox(0,"deviceType:",DllStructGetData($tSearchDevice,"deviceType"))

        EndIf
Else
    Msgbox(0, "DllOpen", "DllOpen failed")
EndIf

DllClose($hDll)

 

 

The API Documentation says under DEVICE_Search:

DEVICE_Search Searches for connectable devices (user buffers)
Declaration: ReturnStatus DEVICE_Search(int* numDevicesFound, int deviceIDs[],
char deviceSerial[][DEVSRCH_SERIAL_MAX_STRLEN], char
deviceType[][DEVSRCH_TYPE_MAX_STRLEN]);

 

Maybe someone can point me in the right direction ?

I think my problem is to understand the DllStructCreate Part... I found a cpp example project, where the variables were declared like this. I think i just dont know how to translate that for my DllStruct...

 
	int numFound = 0;
	int* deviceIDs;
	const char** deviceSerial;
	const char** deviceType;
	char apiVersion[200];

 

Thanks for helping me!

Edited by TwoBeAss
additional info
Posted
19 hours ago, TwoBeAss said:
 

	int numFound = 0;
	int* deviceIDs;
	const char** deviceSerial;
	const char** deviceType;
	char apiVersion[200];

 

Your example specifies numFound yet your code has numDevicesFound... could that be your problem?

Posted

Hello. Seems to be you don't need structures. Could you share the C++/C Example.

 

Saludos

 

 

 

 

Posted (edited)

@dmob, nope, you can use any varname you want afaik...

@Danyfirex im trying to implement the RSA API from Tectronix.. Here you find an example in c++

https://github.com/tektronix/RSA_API/blob/master/C%2B%2B/rsa_api_cpp/consumers.cpp

there are also other examples in c#, python and vb.net... i just want to use autoit for my little tool... Would be great if sb can point me in the right direction !

You find the RSA_API.h attached

Thanks

RSA_API.h

Edited by TwoBeAss
Posted

Hello Maybe something like this would work.

#include <MsgBoxConstants.au3>

Global $hDll = DllOpen("RSA_API.dll")

If $hDll <> -1 Then
    Local $aCall = DllCall($hDll, "int:cdecl", "DEVICE_GetAPIVersion", "str*", Null)
    Local $sAPIVersion = $aCall[1]
    ConsoleWrite("APIVersion: " & $sAPIVersion & @CRLF)
    $aCall = DllCall($hDll, "int:cdecl", "DEVICE_SearchInt", "int*", 0, "ptr*", 0, "ptr*", 0, "ptr*", 0)
    Local $iNumberOfDevices = $aCall[1]
    ConsoleWrite("NumberOfDevices: " & $iNumberOfDevices & @CRLF)
    ;here you will need to cast the information from the pointers
    ;$aCall[2] ;here is maybe DllStructCreate("int[10]",$aCall[2])
    ;$aCall[3] ;here is maybe DllStructCreate("ptr[NumberofDevices]",$aCall[3])
    ;$aCall[4] ;here is maybe DllStructCreate("ptr[NumberofDevices]",$aCall[4])
    ;then get data(string) from each pointer.

Else
    MsgBox(0, "DllOpen", "DllOpen failed")
EndIf

DllClose($hDll)

 

Saludos

Posted

Seems some kind of working! Thanks a lot Danyfirex... $aCall[2] for example, points to a Adress.. Now i just need to figure out, how to reveal the Array behind it...

Posted

Im still stucked in the middle of this...

Im just getting back the Memory Adresses and i dont know how to get to the real data i need... Maybe someone has another hint for me...

 

Local $iNumberOfDevices = $aCall[1]
    ConsoleWrite("NumberOfDevices: " & $iNumberOfDevices & @CRLF)
    $tempstruct = DllStructCreate("int[10]",$aCall[2])
    $result = DllStructGetData($tempstruct,1)
    ConsoleWrite("DeviceIDs: " & $result & @CRLF)
    $tempstruct2 = DllStructCreate("ptr[1]",$aCall[3])
    $result2 = DllStructGetData($tempstruct2,1)
    ConsoleWrite("DeviceSerials: " & $result2 & @CRLF)

This returns just:

NumberOfDevices: 1
DeviceIDs: 0
DeviceSerials: 0x7B266AC0

Posted

Hello. then you need to get the string from pointer.

 

Local $tString=DllStructCreate("char[100]",0x7B266AC0)
ConsoleWrite(DllStructGetData($tString,1) & @CRLF)

 

Saludos

 

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...