Jump to content

CallDLL : Help for my first test :)


 Share

Recommended Posts

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.

 

 

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

 

For sure, you'll see my error, but I didn't :)

 

Thank you for your support ;)

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

Link to comment
Share on other sites

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
Link to comment
Share on other sites

30 minutes ago, 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

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

Link to comment
Share on other sites

2 hours ago, Nine said:

Have you tried to use "cdecl" (see help file under DllCall) ?

Yes I already tried that, without success.

I really think the DotNet DLL is the origin of the issue... and the error message

Link to comment
Share on other sites

1 hour ago, 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

Then you might need to try some of the suggestions found in this thread. :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...