smcombs Posted March 29, 2009 Share Posted March 29, 2009 (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 March 29, 2009 by smcombs Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 30, 2009 Share Posted March 30, 2009 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. Link to comment Share on other sites More sharing options...
smcombs Posted April 4, 2009 Author Share Posted April 4, 2009 (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.dllThen 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.dllThis 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 April 4, 2009 by smcombs Link to comment Share on other sites More sharing options...
zfisherdrums Posted April 4, 2009 Share Posted April 4, 2009 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.dllThen 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.dllThis 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. Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog... Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 4, 2009 Share Posted April 4, 2009 The .Net framework has tons of commands to reference unmanaged resources. You just don't know how to find them. Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 4, 2009 Share Posted April 4, 2009 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. Link to comment Share on other sites More sharing options...
MichaelCowan Posted July 6, 2009 Share Posted July 6, 2009 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? Link to comment Share on other sites More sharing options...
MichaelCowan Posted July 6, 2009 Share Posted July 6, 2009 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. Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 6, 2009 Share Posted July 6, 2009 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. Link to comment Share on other sites More sharing options...
wjshome Posted July 7, 2009 Share Posted July 7, 2009 great help. thanks, mite. Link to comment Share on other sites More sharing options...
MichaelCowan Posted July 7, 2009 Share Posted July 7, 2009 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#. Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 7, 2009 Share Posted July 7, 2009 If that were the opinion of the forum, I'd have been banned a long time ago. Link to comment Share on other sites More sharing options...
AC130 Posted July 16, 2012 Share Posted July 16, 2012 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! Link to comment Share on other sites More sharing options...
AC130 Posted July 17, 2012 Share Posted July 17, 2012 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now