Jump to content

Recommended Posts

Posted

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 ;)

Posted

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.

Posted
Posted (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 by genius257
Posted
  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 :)

Posted

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.

Posted
  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

Posted
  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. :)

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...