sp00ky Posted January 3, 2023 Posted January 3, 2023 Dear forum, I really appreciate this forum because I can find everything I need. But today I try for the first time the CallDLL function, without success. The software I want to connect use DLL, and the manual mentions: Quote 7.2 Function Overview public int OpenConnection(byte[] ipAdr, int Port) Parameters: byte[] ipAdr is the IP address (ipv4) of the laserDESK server, most significant byte first (e.g. 127.0.0.1 corresponds to byte[0] = 127, byte[1] = 0, byte[2] = 0, byte[3] = 1). Port is the port number of the connection. It has to be defined in the laserDESK ’Hardware Configuration’ page too. Function: The method opens a TCP/IP connection to the laserDESK server and sends the login command. This command has to be executed prior to all other commands. Return value: 1 = success, 0 = error. Expand So I wrote this code: #include <Inet.au3> #include <Array.au3> Global $hDll = DllOpen("C:\Program Files\SCANLAB\laserDesk\Remote\SLLDRemoteControl.dll") Local $adr[4]; $adr[0] = 127; $adr[1] = 0; $adr[2] = 0; $adr[3] = 1; Local $Port = 5000 Global $return = DllCall($hDll, "int", "OpenConnection", "byte", $adr, "int", $Port) Report($return[0]) DllClose($hDll) Func Report($report) Return ConsoleWrite("Return: " & $report & @CRLF) EndFunc ;==>Report The ip is 127.0.0.1, and port 5000. While trying my code, the log returns: Quote Report($return[0]) Report($return^ ERROR Expand For sure, you'll see my error, but I didn't Thank you for your support
Danp2 Posted January 3, 2023 Posted January 3, 2023 From the help file -- Quote If the function call fails then @error is set to non-zero. Otherwise an array is returned that contains the function return value and a copy of all the parameters (including parameters that the function may have modified when passed by reference). Expand So you should check the value of @error before accessing the variable as an array. P.S. You may need to use a structure to represent the array for the DLLCall to work correctly. See DllStructCreate in the help file. Latest Webdriver UDF Release Webdriver Wiki FAQs
Danyfirex Posted January 4, 2023 Posted January 4, 2023 Can You Share DLL documenattion? Saludos Danysys.com AutoIt... Reveal hidden contents UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
sp00ky Posted January 4, 2023 Author Posted January 4, 2023 On 1/4/2023 at 11:38 AM, Danyfirex said: Can You Share DLL documenattion? Saludos Expand For sure, here's the file laserDESK_RemoteControl.en.pdfFetching info...
sp00ky Posted January 4, 2023 Author Posted January 4, 2023 On 1/4/2023 at 11:38 AM, Danyfirex said: Can You Share DLL documenattion? Saludos Expand And maybe the DLL file too (if you wish to try anything) SLLDRemoteControl.dllFetching info...
genius257 Posted January 4, 2023 Posted January 4, 2023 (edited) Hi @sp00ky. It seems at least one problem is the first parameter sent to the OpenConnection method. You provide an array to the DllCall, but this is not supported by AutoIt3. I have not tested the code below, but something like this is needed to pass an array of bytes to DllCall. (not sure if the type should be struct or struct*) Local $adr = DllStructCreate("BYTE[4]") DllStructSetData($adr, 1, 127, 1) DllStructSetData($adr, 1, 0, 2) DllStructSetData($adr, 1, 0, 3) DllStructSetData($adr, 1, 1, 4) Local $Port = 5000 Global $return = DllCall($hDll, "int", "OpenConnection", "STRUCT", $adr, "int", $Port) hope it helps Edited January 4, 2023 by genius257 To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
sp00ky Posted January 4, 2023 Author Posted January 4, 2023 On 1/4/2023 at 1:21 PM, genius257 said: Hi @sp00ky. It seems at least one problem is the first parameter sent to the OpenConnection method. You provide an array to the DllCall, but this is not supported by AutoIt3. I have not tested the code below, but something like this is needed to pass an array of bytes to DllCall. (not sure if the type should be struct or struct*) Local $adr = DllStructCreate("BYTE[4]") DllStructSetData($adr, 1, 127, 1) DllStructSetData($adr, 1, 0, 2) DllStructSetData($adr, 1, 0, 3) DllStructSetData($adr, 1, 1, 4) Local $Port = 5000 Global $return = DllCall($hDll, "int", "OpenConnection", "STRUCT", $adr, "int", $Port) hope it helps Expand no, unfortunately, it doesn't work. If I edit the DLL, I found the function: public int OpenConnection(ref byte[] ipAdr, int Port) { if (this.once) return 0; try { this.InitializeConnection(ipAdr, Port); byte[] data = TelegramBuilder.MakeCommand(1, (object) "1990"); if (data == null) return 0; SLAnswer ca; if (this.SendAndReceive(out ca, data) != 1) ca.cmd = 0; if (ca.cmd == 1) { int retVal = this.retVal; this.GetVersion(); return retVal; } if (ca.cmd == 0 || ca.cmd == 1) return 0; this.m_transmission_error |= 2; return 0; } catch { this.th.m_go = false; return -1; } } Maybe it can help
sp00ky Posted January 4, 2023 Author Posted January 4, 2023 I think I found the problem: My DLL is in .NET, and use class... I probably need to look for solutions to implement .NET in Autoit.
Nine Posted January 4, 2023 Posted January 4, 2023 Have you tried to use "cdecl" (see help file under DllCall) ? “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
sp00ky Posted January 4, 2023 Author Posted January 4, 2023 On 1/4/2023 at 6:45 PM, Nine said: Have you tried to use "cdecl" (see help file under DllCall) ? Expand Yes I already tried that, without success. I really think the DotNet DLL is the origin of the issue... and the error message
genius257 Posted January 4, 2023 Posted January 4, 2023 On 1/4/2023 at 9:23 PM, sp00ky said: Yes I already tried that, without success. I really think the DotNet DLL is the origin of the issue... and the error message Expand Then you might need to try some of the suggestions found in this thread. To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
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