Jump to content



Photo

Create a DLL in C# for autoit


  • Please log in to reply
7 replies to this topic

#1 frankito

frankito

    Seeker

  • Active Members
  • 17 posts

Posted 12 December 2009 - 01:04 AM

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







#2 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,716 posts

Posted 12 December 2009 - 06:08 AM

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.

#3 frankito

frankito

    Seeker

  • Active Members
  • 17 posts

Posted 12 December 2009 - 11:56 AM

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

#4 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,716 posts

Posted 12 December 2009 - 10:21 PM

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.
  • zpanderson likes this

#5 zpanderson

zpanderson

    Seeker

  • Active Members
  • 33 posts

Posted 01 July 2012 - 03:29 PM

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, 01 July 2012 - 10:58 PM.


#6 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,716 posts

Posted 02 July 2012 - 02:01 PM

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

#7 zpanderson

zpanderson

    Seeker

  • Active Members
  • 33 posts

Posted 03 July 2012 - 03:06 PM

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, 03 July 2012 - 03:11 PM.


#8 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,716 posts

Posted 03 July 2012 - 06:33 PM

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, 03 July 2012 - 06:35 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users