Sign in to follow this  
Followers 0
frankito

Create a DLL in C# for autoit

8 posts in this topic

Hi everyone,

i want to create a C# (or VB.net) DLL and use it in autoit.

I just want my DLL return a large string to my autoit EXE.

I didn't find any tuto about it, is that possible ?

Thanks

Share this post


Link to post
Share on other sites



It's not. AutoIt cannot access the .Net framework directly. It can only call native resources.

You can instead create a COM object from your .Net class and use that.

Share this post


Link to post
Share on other sites

like this ? http://www.autoitscript.com/forum/index.php?showtopic=39262

my purpose is quite simple i just want to encrypt a large string in a DLL and deserve it to my autoit exe.

Like this :

My DLL :

GetMyString() {

return string

}

My EXE :

Call ("mydll","getMyString")

I know it's not as simple as i could write, but i'm litlle bit lost...

thanks

Share this post


Link to post
Share on other sites

No, you're looking in the right place but the wrong direction.

You said you wanted to use C#, so I assume you know enough about Visual Studio to follow this.

[COMVisible(true)]
public class MyCOMClass
{
    public string GetMyString(string someparameter)
    {
        return someparameter;
    }
}

Compile this to "mydll.dll".

Then call "regasm.exe /codebase mydll.dll".

In AutoIt,

$obj = ObjCreate("mydll.MyCOMClass")
$mystring = $obj.GetString("Hello!")

One or more of these steps may need tweaking, but I hope I've at least given you a step in the right direction.

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Compile this to "mydll.dll".

Then call "regasm.exe /codebase mydll.dll".

Am I correct in thinking that this will only allow this solution to work on the computer that it's built on?

Edit:

Well I tested this method out and I have it working on 1 pc and not another. I tried using regasm to generate a registry file for use on the second pc but that didn't seem to help. Any advice on how to get this to work on pcs that it wasn't built on?

Thanks!

Edited by zpanderson

Share this post


Link to post
Share on other sites

You need to make sure that the second computer has the appropriate version of the .Net framework and all dependencies installed.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks a lot for your help on getting this to work.

I do have one more question that you might be able to help with. My c# function takes "public static int put(String[] args)" as an input parameter but I can't figure out how to send this through autoit. I tried making an array of strings, but that doesn't work.

Dim $args[4] = ['OTS.TROUBLECALL.IN', 'OMSDW001', 'SEEBYOND.SVRCONN/TCP/172.19.96.64(1414)', '']

$obj = ObjCreate("nmqput.mqput")
$obj.put($args)

I get a COM Error

err.windescription = Type mismatch.

err.number is: 80020005

err.lastdllerror is: 0

err.scriptline is: -1

err.source is:

err.helpfile is:

err.helpcontext is: 4980844

If I change my c# function to "public static int put(String args)". I can send a singular string with no problems.

Regards,

Edited by zpanderson

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You don't want static functions. You want member functions because you are instantiating an object through COM.

The problem appears to be handling of arrays via COM though. I don't have enough experience in that to say what the problem or solution is.

Edited by Richard Robertson

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