DickWms Posted December 26, 2012 Share Posted December 26, 2012 I need help using AU3_WinGetHandle in a C# Program. My test program is shown below. It runs as expected with the last two lines commented out. But when the with AU3_WinGetHandle is active I get an error message saying "A problem caused the program to stop working correctly." and the only option is to close the program. I would appreciate if if someone points out my mistake. Thank you - Dick Williams expandcollapse popupusing 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.Runtime.InteropServices; namespace TryAutoitDLL { public partial class Form1 : Form { [DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)] static public extern int AU3_AutoItSetOption([MarshalAs(UnmanagedType.LPWStr)] string Option, int Value); [DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)] static public extern void AU3_WinActivate([MarshalAs(UnmanagedType.LPWStr)]string Title, [MarshalAs(UnmanagedType.LPWStr)]string Text); [DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)] static public extern void AU3_WinGetHandle([MarshalAs(UnmanagedType.LPWStr)]string Title, [MarshalAs(UnmanagedType.LPWStr)]string Text, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder RetText, int BufSize); [DllImport("AutoItX3.dll", SetLastError = true, CharSet = CharSet.Auto)] static public extern int AU3_ControlSend([MarshalAs(UnmanagedType.LPWStr)] string Title, [MarshalAs(UnmanagedType.LPWStr)] string Text, [MarshalAs(UnmanagedType.LPWStr)] string Control, [MarshalAs(UnmanagedType.LPWStr)] string SendText, int Mode); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { AU3_AutoItSetOption("WinTitleMatchMode", 2); AU3_WinActivate("Notepad", ""); StringBuilder handle = new StringBuilder(); //AU3_WinGetHandle("Untitled - Notepad", "", handle, 200); //int i = AU3_ControlSend("", "", handle.ToString(), "aaaa", 0); } } } Link to comment Share on other sites More sharing options...
GideonM Posted April 11, 2013 Share Posted April 11, 2013 Are you aware that autoit uses the user32.dll? see http://stackoverflow.com/questions/3787057/need-to-activate-a-window http://igify.com/?q=visual+c%23+activate+window+by+handle Link to comment Share on other sites More sharing options...
JohnOne Posted April 11, 2013 Share Posted April 11, 2013 Does AU3_WinGetHandle not take just two parameters? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 11, 2013 Share Posted April 11, 2013 Logically, it would have to take three. One for the input, and two describing the output buffer. First being the buffer and the second being the length. Link to comment Share on other sites More sharing options...
JohnOne Posted April 14, 2013 Share Posted April 14, 2013 I thought it just returned a string representation of the window handle, and only took title and text as parameters. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 14, 2013 Share Posted April 14, 2013 You can't return a string in C.That is just asking for trouble. Link to comment Share on other sites More sharing options...
JohnOne Posted April 14, 2013 Share Posted April 14, 2013 Just the help file is misleading. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted April 14, 2013 Share Posted April 14, 2013 Have not used AutoItx with C# for a long time, or C# for that matter. But perhaps you might want to specify a size. StringBuilder handle = new StringBuilder("",32); AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 14, 2013 Share Posted April 14, 2013 It's actually just easier to pass a char[] and to make a string out of it just call new string(buffer). 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