Sign in to follow this  
Followers 0
smcombs

Trouble referencing AutoItX3.dll in C#

14 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

great help. thanks, mite.

Share this post


Link to post
Share on other sites

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#.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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

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