Jump to content
Sign in to follow this  
AngelsFlyHigh

Use a .NET (v 4.0) DLL from AutoIt ?

Recommended Posts

AngelsFlyHigh

Hi!

New to using DLL's from AutoIt so hopefully this is a easy one to answer.

When you have a COM DLL all you need to to is using the DLLCall or DLLOpen to start using it. But in my case the developer says the DLL I'm want to use is a .NET DLL and it lacks the COM parts in it.

Some basic tries using DLLOpen always return @error = 4.

Anyone have any experience with these "new" kinds of DLL's? Can they be accesses from AutoIt at all? The developer says I probably need some Wrapper to access the DLL. Basically making it a COM DLL. Anyone who have some insights to create/download a Wrapper that can use a .NET v4.0 DLL?

Kind Regards,

Thomas


Never underestimate the power of random clicking!

Share this post


Link to post
Share on other sites
AngelsFlyHigh

Its a custom built DLL called "ServiceProvider.DLL" that creates a connection to a database.This DLL is used to fetch data about companies here in Denmark.


Never underestimate the power of random clicking!

Share this post


Link to post
Share on other sites
dragan

If you want to make it COM accessible, then >look here.

If you want to make a standard DLL, then continue reading:

Have you ever heard of a "Unmanaged Exports" library for .NET?
Add it to your .NET project, and form the function something like:

class Class1
{
    [DllExport("add", CallingConvention = CallingConvention.StdCall)]
    public int AddNumbers(int a, int b)
    {
        return a + b;
    }

    [DllExport("sub", CallingConvention = CallingConvention.StdCall)]
    public int SubtractNumbers(int a, int b)
    {
        return a - b;
    }

    [DllExport("multistring", CallingConvention = CallingConvention.StdCall)]
    public string MultiString(string str1, string spc = ",", int b = 1)
    {
        if (str1.Length < 1 || b < 1) return "";

        string retVal = "";

        for (int i = 1; i <= b; i++)
        {
            retVal += str1 + spc;
        }

        if (spc.Length <= 0)
             return retVal;
        else
            return retVal.Remove(retVal.Length - spc.Length, spc.Length);
    }
}

And you would have to add references:

using System.Runtime.InteropServices;
using RGiesecke.DllExport;

And then compile as DLL for x86 OR x64 platform (If you leave the "Any CPU" platform, the functions will not be exported), and use it from your autoit as:

$myDLL = @ScriptDir & '\myNETdll.dll'
if NOT FileExists($myDLL) Then Exit

$dllCall1 = DllCall($myDLL, 'int', 'add', 'int', 5, 'int', 7)
if @error Then
    MsgBox(0, 'Error', 'Error code: ' & @error)
Else
    MsgBox(0, 'ADD Result', $dllCall1[0])
EndIf

$dllCall2 = DllCall($myDLL, 'int', 'sub', 'int', 20, 'int', 14)
if @error Then
    MsgBox(0, 'Error', 'Error code: ' & @error)
Else
    MsgBox(0, 'SUB Result', $dllCall2[0])
EndIf

$dllCall3 = DllCall($myDLL, 'str', 'multistring', 'str', 'SOME_TEXT', 'str', ',', 'int', 3)
if @error Then
    MsgBox(0, 'Error', 'Error code: ' & @error)
Else
    MsgBox(0, 'MULTISTRING Result', $dllCall3[0])
EndIf

p.s. none of the examples were tested, but it should work as I've done this before.

Edited by dragan
  • Like 1

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  

×