Jump to content



Photo

Trouble referencing AutoItX3.dll in C#


  • Please log in to reply
13 replies to this topic

#1 smcombs

smcombs

    Wayfarer

  • Active Members
  • Pip
  • 68 posts

Posted 29 March 2009 - 08:19 PM

Ok I have my C# program made just as a button click to activate a window for testing. I have AutoItX3.dll as a reference and a resource but my code is failing whenever I run the .exe outside of its build folder. Which I believe is because its still trying to reference the .dll. How do I access the .dll inside my program so it wont require the .dll

Here is my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Resources;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
static AutoItX3Lib.AutoItX3Class au3;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
au3 = new AutoItX3Lib.AutoItX3Class();
au3.WinActivate("Untitled - Notepad", "");
}

}
}

So far this works great if the .exe. I think I need to use something like Getmanifest but I am not sure how to incorporate it.

Edited by smcombs, 29 March 2009 - 08:21 PM.






#2 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,692 posts

Posted 30 March 2009 - 05:28 AM

You can't. It needs the dll externally for the automagic linking to occur. If you want it embedded, that's an exponentially more complicated thing to do.

#3 smcombs

smcombs

    Wayfarer

  • Active Members
  • Pip
  • 68 posts

Posted 04 April 2009 - 05:27 AM

Ok found my answer!!! Finally.

First, I have 64 bit vista and apparently whenever I installed AutoIt the AutoItX3.dll did not get registered. So if you are not able to create the "static AutoItX3Lib.AutoItX3Class au3;" from the below reference its probably because its not registered and you just made a reference to the .dll itself. So go to Add Reference after the AutoItX3.dll is registered and lookin COM and you will see the AutoItX3 1.0 Type Library. Add that as the reference. If you have xp this shouldnt be a problem.

Here is what you need to register your .dll: regsvr32 "C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.dll" you will get a message box telling you it was successful.

Then reference this guys post for adding in your AutoIt functions. Here: http://www.autoitscript.com/forum/index.ph...hl=AutoItX3.dll

Then do this magic, this is the key! Download iLmerge and install it. Go to your C# and in your project go to Project > (Whatever your project name).Properties which should be the last option in your menu. Once you click it go to the Build Events tab. And click on post-build and enter in this code:

"C:\Program Files\Microsoft\ILMerge\ilmerge" /target:winexe /out:Autoittest-merge.exe Autoittest.exe Interop.AutoItX3Lib.dll

This will build the AutoItX3.dll straight into your application. You need to build it twice because after the first build it loads the Interop.AutoItX3Lib.dll into the directory and then on the second build it will create your combined .exe which should output to be Autoittest-merge.exe which is just a name I created. And Autoittest.exe is just my project name so this is name whatever your project is called or saved as rather. Since all this has been done, all you need to do is code and build and it will compile only the functions you add. So now enjoy the POWER!

Edited by smcombs, 04 April 2009 - 05:59 AM.


#4 zfisherdrums

zfisherdrums

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 391 posts

Posted 04 April 2009 - 07:38 AM

Ok found my answer!!! Finally.

First, I have 64 bit vista and apparently whenever I installed AutoIt the AutoItX3.dll did not get registered. So if you are not able to create the "static AutoItX3Lib.AutoItX3Class au3;" from the below reference its probably because its not registered and you just made a reference to the .dll itself. So go to Add Reference after the AutoItX3.dll is registered and lookin COM and you will see the AutoItX3 1.0 Type Library. Add that as the reference. If you have xp this shouldnt be a problem.

Here is what you need to register your .dll: regsvr32 "C:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.dll" you will get a message box telling you it was successful.

Then reference this guys post for adding in your AutoIt functions. Here: http://www.autoitscript.com/forum/index.ph...hl=AutoItX3.dll

Then do this magic, this is the key! Download iLmerge and install it. Go to your C# and in your project go to Project > (Whatever your project name).Properties which should be the last option in your menu. Once you click it go to the Build Events tab. And click on post-build and enter in this code:

"C:\Program Files\Microsoft\ILMerge\ilmerge" /target:winexe /out:Autoittest-merge.exe Autoittest.exe Interop.AutoItX3Lib.dll

This will build the AutoItX3.dll straight into your application. You need to build it twice because after the first build it loads the Interop.AutoItX3Lib.dll into the directory and then on the second build it will create your combined .exe which should output to be Autoittest-merge.exe which is just a name I created. And Autoittest.exe is just my project name so this is name whatever your project is called or saved as rather. Since all this has been done, all you need to do is code and build and it will compile only the functions you add. So now enjoy the POWER!


Great find! All the MSDN'ing Google-foo'ing I tried led me to believe that referencing unmanaged resources and their exported functions was nay impossible. Enjoy your success.

#5 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,692 posts

Posted 04 April 2009 - 02:51 PM

The .Net framework has tons of commands to reference unmanaged resources. You just don't know how to find them.

#6 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,692 posts

Posted 04 April 2009 - 09:13 PM

No. I've made calls to COM objects, dlls, and even wrote a bridge between a java application I wrote and a native C++ dll.

#7 MichaelCowan

MichaelCowan

    Seeker

  • Active Members
  • 5 posts

Posted 06 July 2009 - 05:22 PM

The .Net framework has tons of commands to reference unmanaged resources. You just don't know how to find them.


Wow, seriously, wow.

Again, good job on padding your post count without providing anything of value. I really like how you remove the quotes from your responses so your posts are disjointed even in small threads like this. The real genius is in the multiple replies, all those people editing their own replies are wasting post counts .. just post another reply, right?

#8 MichaelCowan

MichaelCowan

    Seeker

  • Active Members
  • 5 posts

Posted 06 July 2009 - 05:25 PM

Ok found my answer!!! Finally.
...
...
...
So now enjoy the POWER!


Thanks for clearing this up, I have never used ILMerge before, I think that tip alone is going to come in really handy for a lot of people on many different projects. Nice write up as well, thanks.

#9 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,692 posts

Posted 06 July 2009 - 05:31 PM

I like how the only thing you've done since joining this forum is badmouth me.

I don't quote posts because I don't expect them to disappear. I don't double post like that.

#10 wjshome

wjshome

    Seeker

  • New Members
  • 2 posts

Posted 07 July 2009 - 12:23 AM

great help. thanks, mite.

#11 MichaelCowan

MichaelCowan

    Seeker

  • Active Members
  • 5 posts

Posted 07 July 2009 - 04:04 PM

I like how the only thing you've done since joining this forum is badmouth me.

I don't quote posts because I don't expect them to disappear. I don't double post like that.


I only came to the forums because I wanted to combine C# and AutoIt. Then I noticed that in every single thread I found on the subject you had posted some rude comment to the OP and/or other members. I also noticed that everyone just ignores you, so I decided to say what needed to be said, you are an asshole and a jerk. Not one of the posts of yours I have read has added any real value, you simply talked down to good people.

Well, thanks to non-asshole members of the community I got my questions answered and I have auto-it working just fine from C#.

#12 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 9,692 posts

Posted 07 July 2009 - 11:59 PM

If that were the opinion of the forum, I'd have been banned a long time ago.

#13 AC130

AC130

    Adventurer

  • Active Members
  • PipPip
  • 143 posts

Posted 16 July 2012 - 03:26 AM

I did all of the above and whenever I goto start my application, I receieve "... Has encountered an error and needs to close". I registered the dll and I got the correct message box. I added AutoIt as a reference. I added the post-build event. I built the exe. I got the new exe. I start it, and boom, the error. Why is it so hard to use the damn dll without registering!

#14 AC130

AC130

    Adventurer

  • Active Members
  • PipPip
  • 143 posts

Posted 17 July 2012 - 04:57 PM

Error 1 The command ""C:Program Files (x86)MicrosoftILMergeilmerge" /target:winexe /out:Autoittest-merge.exe OK.exe" Interop.AutoItX3Lib.dll" exited with code 1. OK




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users