MagicSpark Posted May 4, 2017 Posted May 4, 2017 (edited) Hello, can someone help me out with some DllCall in AU3. The relevant source of function and struct definition are as follows (in slightly modified form): typedef struct { char *host; char *key; char *value; } test_sender_value_t; /****************************************************************************** * Parameters: address - [IN] server address * * port - [IN] server port * * source - [IN] source IP, optional - can be NULL * * values - [IN] array of values to send * * count - [IN] number of items in values array * * result - [OUT] the server response/error message, optional * * * * Return value: 0 - the values were sent successfully, result contains * * server response * * -1 - an error occurred, result contains error message * * * ******************************************************************************/ TEST_API int test_sender_send_values(const char *address, unsigned short port, const char *source, const test_sender_value_t *values, int count, char **result); In AutoIt I use the following code to build the struct and call the dll: Global $struct = DllStructCreate("ptr ptrtostring1;ptr ptrtostring2;ptr ptrtostring3;") Global $string1 = DllStructCreate("char host[255];") DllStructSetData($string1, "host", "Test_Client") DllStructSetData($struct, "ptrtostring1", DllStructGetPtr($string1)) Global $string2 = DllStructCreate("char key[255];") DllStructSetData($string2, "key", "clientver") DllStructSetData($struct, "ptrtostring2", DllStructGetPtr($string2)) Global $string3 = DllStructCreate("char value[255];") DllStructSetData($string3, "value", "123456") DllStructSetData($struct, "ptrtostring3", DllStructGetPtr($string3)) Global $aCall = DllCall("C:\temp\test.dll", "int", "test_sender_send_values", _ "str", "192.168.1.2", _ "int", 80, _ "str", "192.168.1.3", _ "ptr", DllStructGetPtr($struct), _ "int", 1) If @error Then ConsoleWrite("Error: " & @error & @CRLF) exit 1 Else ConsoleWrite("Success: " & $aCall[0] & @CRLF) EndIf If I ran the AU3-Script with SciTE I get the following output: !>12:00:00 AutoIt3.exe ended.rc:-1073741783 Can someone point me into the right direction. I must admit, that I'm very new to handling DLL-Calls and structs. But I've read down the forum threads and the AutoIt help. Thanks in advance. Edited May 4, 2017 by MagicSpark
spudw2k Posted May 4, 2017 Posted May 4, 2017 @MagicSpark I'm not an expert at DLL calls either, but I see that your fourth parameter (values) says it is expecting an array of values; so I'm not sure if providing a ptr is appropriate. That's about the only hunch I have...sorry if it leads nowhere. 4 hours ago, Mugen said: where is the result parameter in your call? Should be optional per the description of the DLL function, yes? Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
trancexx Posted May 5, 2017 Posted May 5, 2017 ^^ "Optional" doesn't mean optional in such way. What it really means is that (C/C++) compiler will generate the argument for programmer if omitted - as per definition. Obviously, AutoIt is not C compiler, therefore "optional" means nothing here. It should be: DllCall("C:\temp\test.dll", "int", "test_sender_send_values", _ "str", "192.168.1.2", _ "ushort", 80, _ "str", "192.168.1.3", _ "ptr", DllStructGetPtr($struct), _ "int", 1, _ "ptr*", 0) If that fails for some reason, then calling convention should be changed to cdecl ("int:cdecl"), because it's not obvious from the OP what TEST_API is. Biatu and spudw2k 2 ♡♡♡ . eMyvnE
MagicSpark Posted May 5, 2017 Author Posted May 5, 2017 Thank you so much! Especially trancexx's post help me alot. The DllCall works now with these code changes: DllCall("C:\temp\test.dll", "int:cdecl", "test_sender_send_values", _ "str", "192.168.1.2", _ "ushort", 80, _ "str", "192.168.1.3", _ "ptr", DllStructGetPtr($struct), _ "int", 1, _ "ptr*", 0) I now try to get the other needed functions in that .dll to work by myself. I get back to you, if I need further help. Thanks again.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now