Markus W Posted April 2, 2009 Share Posted April 2, 2009 I'm having a hard time with calling a DLL. The examples I found only cover strings in that matter. The DLL expects a char* as a parameter and delievers its result back into that area. int MyFunc (char *chBuf, int Size); This could be the correct invocation, but if chBuf contains binary zeros the string is trimmed: $RetVal = "AAAAAAAAAAAAAAAAAAAAAAAAAAA" $Read = DllCall ($DLLHandle, "int:stdcall", "MyFunc", "str", $RetVal, "int", 10) MsgBox (0, "Test", "RetVal: " & $Read [1]) shows, for example: 12345 Nothing wrong, so far, but in reality I get back from the DLL: "12345" '\0' '\0' "678" The binary zeros don't appear in the AutoIt string variable. If I use Binary ($Read [1]) the result stays the same except that I get its hexadecimal representation back, but the buffer is still trimmed. I tried to make it binary, like, $Read = DllCall ($DLLHandle, "int:stdcall", "MyFunc", "ptr", $RetVal, "int", 10) but I don't know how to provide $RetVal's address instead of its value (I always receive the value 0 back, which is of course correct because I'm not referencing the pointer). In C/C++ I'd use the ampersand character (&RetVal). Is there a similar way in AutoIt script? Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 2, 2009 Share Posted April 2, 2009 (edited) What about: $RetVal = DllStructCreate("char[128]") $Read = DllCall($DLLHandle, "int:stdcall", "MyFunc", "ptr", DllStructGetPtr($RetVal), "int", 10) MsgBox(0, "Test", "RetVal: " & DllStructGetData($RetVal, 1)) WBD Edited April 2, 2009 by WideBoyDixon [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
ProgAndy Posted April 2, 2009 Share Posted April 2, 2009 (edited) if the functions returns binary data with zeros, you should use byte instead of char $RetValSize = 128 $RetVal = DllStructCreate("byte[" & $RetValSize & "]") ; set string to binary struct: DLLStructSetData($RetVal,StringToBinary("A test string")) $Read = DllCall($DLLHandle, "int:stdcall", "MyFunc", "ptr", DllStructGetPtr($RetVal), "int", $RetValSize) MsgBox(0, "Test", "RetVal: " & DllStructGetData($RetVal, 1)) Edited April 2, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 2, 2009 Share Posted April 2, 2009 Oh I see. I thought the nulls were discardable; not part of the actual required result! [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
Markus W Posted April 2, 2009 Author Share Posted April 2, 2009 if the functions returns binary data with zeros, you should use byte instead of char $RetValSize = 128 $RetVal = DllStructCreate("byte[" & $RetValSize & "]") ; set string to binary struct: DLLStructSetData($RetVal,StringToBinary("A test string")) $Read = DllCall($DLLHandle, "int:stdcall", "MyFunc", "ptr", DllStructGetPtr($RetVal), "int", $RetValSize) MsgBox(0, "Test", "RetVal: " & DllStructGetData($RetVal, 1))Thanks a lot, both of you! That solved it. I didn't expect that it may be so complicated, I only kept looking for a simple solution. ;-) Link to comment Share on other sites More sharing options...
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