Sign in to follow this  
Followers 0
=sinister=

Help Calling a Dll

11 posts in this topic

I need some help calling the dll. The main problem is that its return type is TrueLocation and I have no clue what that is ??

public TrueLocation convertCoordinates(int zoneID, double wowX, double wowY)

^

Here is the method.

I tried this but it keeps returning 0:

$Dll = DllOpen("./CoordsConvert.dll")
$Test = DllCall($Dll, "TrueLocation", "convertCoordinates", "int", 3520, "double", 32.91302, "double", 33.69269)
MsgBox(0, "Test", $Test)
DllClose($Dll)

Share this post


Link to post
Share on other sites



Might take a trip to the help file and see if dllcall allows for the "double" type. :) ... might try "float" instead.

You also seem to forget that $Test will be an array, so of course the value will be blank calling it as a plain variable.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I need some help calling the dll. The main problem is that its return type is TrueLocation and I have no clue what that is ??

public TrueLocation convertCoordinates(int zoneID, double wowX, double wowY)

^

Here is the method.

I tried this but it keeps returning 0:

$Dll = DllOpen("./CoordsConvert.dll")
$Test = DllCall($Dll, "TrueLocation", "convertCoordinates", "int", 3520, "double", 32.91302, "double", 33.69269)
MsgBox(0, "Test", $Test)
DllClose($Dll)
More information is needed as the issue is with the CoordsConvert.dll. I have no knowledge of this DLL and can't assist without having access to the dll's api documentation. Edited by Zinthose

--- TTFN

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hrm, but setting it as if it is an array leads to a "Subscript used with non-Array variable."

--edit--

here is the method source, but it's not the full dll (duh): Written in C#

public TrueLocation convertCoordinates(int zoneID, double wowX, double wowY)
        {
            foreach (Zone z in zonePack)
            {
                if (z.getZoneID() == zoneID)
                {
                    double pctWidthValue = z.getWidth() / 100;
                    double pctHeightValue = z.getHeight() / 100;

                    double xValue = z.getUpperLeftX() - (pctWidthValue * wowX);
                    double yValue = z.getUpperLeftY() - (pctHeightValue * wowY);


                    return new TrueLocation(xValue, yValue);
                }
            }
            return null;
        }
Edited by =sinister=

Share this post


Link to post
Share on other sites

Hrm, but setting it as if it is an array leads to a "Subscript used with non-Array variable."

--edit--

here is the method source, but it's not the full dll (duh): Written in C#

public TrueLocation convertCoordinates(int zoneID, double wowX, double wowY)
        {
            foreach (Zone z in zonePack)
            {
                if (z.getZoneID() == zoneID)
                {
                    double pctWidthValue = z.getWidth() / 100;
                    double pctHeightValue = z.getHeight() / 100;

                    double xValue = z.getUpperLeftX() - (pctWidthValue * wowX);
                    double yValue = z.getUpperLeftY() - (pctHeightValue * wowY);


                    return new TrueLocation(xValue, yValue);
                }
            }
            return null;
        }
You need to know what TrueLocation's return value is. That's a separate function all together, and you're using it as a return type.

Seriously... You need to only use the types of returns allowed by autoit, not what other functions tell you they are.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Sorry, I never really looked into DllCall too much, and I don't know too much C#.

Here is the class:

public class TrueLocation
    {
        public double X;
        public double Y;

        public TrueLocation(double _X, double _Y)
        {
            X = _X;
            Y = _Y;
        }
        public String getPPString()
        {
            String output;
            String temp = Convert.ToString(this.Y);
            if (temp.IndexOf(".") != -1 && (temp.Length >= (temp.IndexOf(".") + 3)))
            {
                temp = temp.Remove(temp.IndexOf(".") + 2);
            }

            // adding to final output
            output = "[" + temp + ", ";

            temp = Convert.ToString(this.X);
            if (temp.IndexOf(".") != -1 && (temp.Length >= (temp.IndexOf(".") + 3)))
            {
                temp = temp.Remove(temp.IndexOf(".") + 2);
            }

            //adding to final output
            output += temp + "]";

            return output;
        }
    }

The only thing is, TrueLocation doesn't have a return??

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

That really looks like horrible coding.

Try this:

$h_dll = DllOpen(".\CoordsConvert.dll")
If $h_dll <> -1 Then
    $a_test = DllCall($Dll, "str", "convertCoordinates", "int", 3520, "float", 32.91302, "float", 33.69269)
    If Not @error Then
        MsgBox(0, "Testing", $a_test[0])
    Else
        MsgBox(16, "Error", "Error calling Dll")
    EndIf
    DllClose($Dll)
Else
    MsgBox(16, "Error", "Error opening Dll")
EndIf

Edit:

That's probably wrong too... I don't see a return value to be honest... are you sure convertCoordinates isn't just for global setting vars within the dll itself? That's what it looks like to me.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well it's a good thing I didn't make it :)

The dll is used by a application written in C# too, but I can't find where the dll is used in the application.

--edit--

(There is an error calling the dll using your script)

Edited by =sinister=

Share this post


Link to post
Share on other sites

Edit:

That's probably wrong too... I don't see a return value to be honest... are you sure convertCoordinates isn't just for global setting vars within the dll itself? That's what it looks like to me.

The return type is the TrueLocation class. Simple as that.

However it gets awfully complicated when you're trying to make it work in AutoIt.

First because it's a C# class and secondly because AutoIt can't return anything else than the standard types from a function in a dll.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Ok what if I add a return value to it and compile it?

Edited by =sinister=

Share this post


Link to post
Share on other sites

Ok what if I add a return value to it and compile it?

Yeah, since it seems that you want to get the x and y values you can just return a pointer to a struct that has a x and y member.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
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
Sign in to follow this  
Followers 0