Sign in to follow this  
Followers 0
SuperEnginerd

Passing array of structs to dllCall, revisited?

4 posts in this topic

#1 ·  Posted (edited)

Hello all. (autoit newbie) I'm having trouble getting the correct return values from my dllcall... thought I'd post and help.

Using the example I found

So I have a function that looks like this:

// function to scan wifi, returns list of APs and number of APs found
DWORD scanwifi(BYTE **ppWifiAPs, DWORD*size)

and ppWifiAPs is an array of structs, like this:

struct {
   WCHAR ssid[260];
   int rssi;
   int auth;
   int priv;
}

so I write my autoit script like this

local $wifi_ap_count = 255
local $wifi_ap_list_print

; build array of structs
$wifi_ap_struct_type = "WCHAR ssid[260];int rssi;int auth;int priv"
$WifiStructDef=""
For $i = 0 to 20
    $WifiStructDef&=$wifi_ap_struct_type;
Next
$wifi_ap_list_array= DllStructCreate($WifiStructDef)

; do the actual call
$result = DllCall("RemoteExerciserDLL.dll", _
                "DWORD:cdecl","scanwifi", _
                "ptr", DllStructGetPtr($wifi_ap_list_array), _
                "DWORD*", $wifi_ap_count)

; set the count of returned number of found APs
$wifi_ap_count = $result[2]

; build the result string
For $j = 0 to $wifi_ap_count
    $wifi_ap_list_print &= _
                "SSID: " & DllStructGetData($wifi_ap_list_array, 4*$j+1) & _
                " RSSI: " & DllStructGetData($wifi_ap_list_array, 4*$j+2) & _
                " Auth: " & DllStructGetData($wifi_ap_list_array, 4*$j+3) & _
                " Priv: " & DllStructGetData($wifi_ap_list_array, 4*$j+4) & @CRLF
Next

MsgBox(0, "ScanWifi", "Finished scanning wifi:" & @CRLF & _
            "return status: " & $result[0] & @CRLF & _
            "Found Networks count: " & $wifi_ap_count & @CRLF & _
            "Found Networks: " & @CRLF & $wifi_ap_list_print )

but this does not seem to work. My "found network count" is always some weird number, and wifi_ap_count seems always to be 0, and the output values are all 0's

I have a C program that calls this function and I am able to get the correct results, but AutoIt seems to always return funny numbers, and I can't quite tell if it got any data back at all... any thoughts?

(sorry if this seems like a cop out to ask you guys to debug my code, but I am just out of ideas of what else to try?)

Edited by SuperEnginerd

Share this post


Link to post
Share on other sites



You have a typo in your dllstruct data set.

Your variable $wifi_ap_struct_type should end with a seperating semicolon ';' to seperate all the terms in the list. When you join it back to back with your for loop statement, it will look like: WCHAR ssid[260];int rssi;int auth;int privWCHAR ssid[260];int rssi;int auth;int privWCHAR ssid[260];int rssi;int auth;int priv

You can see your mistake I assume.

Share this post


Link to post
Share on other sites

Ya...... but at least he can't say the autoit community doesn't care.

Share this post


Link to post
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
Sign in to follow this  
Followers 0