SueImWeb Posted September 16, 2009 Share Posted September 16, 2009 Hello,since yesterday I am trying to use AutoItX by DllImport for the umpteenth time - no success again.It's the same like before, registering the dll and referencing it, there are no problems.Using my old AutoIt.dll from 2002 by DllImport does also work. But using AutoItX V3 by DllImport...nothing happens.Would someone please tell me, what's wrong?This is what I do:1. Stored the AutoItX3.dll into the program folder of my C# Project(tried the system32 folder also).2. Created a class like this one or that one and named it "AutoItX".3. Tried to call different methods....none of them seem to work...Sue Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 16, 2009 Share Posted September 16, 2009 What type are you using for the string parameters? AutoItX was upgraded to Unicode, so your function prototypes will have to match. Link to comment Share on other sites More sharing options...
SueImWeb Posted September 18, 2009 Author Share Posted September 18, 2009 Hello Richard, according to the postings I linked to, I used the type of string. But a few month ago (also with version 3) I also tried it with StringBuilder. The first example shows it like this: [DllImport(dllpath, SetLastError = true, CharSet = CharSet.Auto)] private static extern int AU3_WinExists([MarshalAs(UnmanagedType.LPStr)]string Title, [MarshalAs(UnmanagedType.LPStr)]string Text); public static int WinExists(string vsTitle, string vsText) { return AU3_WinExists(vsTitle, vsText); } Sue Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 18, 2009 Share Posted September 18, 2009 Use UnmanagedType.LPWStr instead. LPStr is a single byte string, while LPWStr is a wide character string. Link to comment Share on other sites More sharing options...
SueImWeb Posted September 19, 2009 Author Share Posted September 19, 2009 (edited) Thank you very much ... that works. But there is one thing left. Using the dll this way I am not able to look for a window by its handle. I tried it in different ways (got the handle through API's GetForegroundWindow method): AU3_WinExists("[HANDLE:" + hWnd.toString() + "]", ""); AU3_WinExists("handle=" + hWnd.toString(), ""); AU3_WinExists(hWnd.toString(), ""); Every call returns 0. Do you have any idea? Sue Edited September 19, 2009 by SueImWeb Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 19, 2009 Share Posted September 19, 2009 What exactly are you trying to do? I may be able to help you do it directly in C#. Link to comment Share on other sites More sharing options...
SueImWeb Posted September 20, 2009 Author Share Posted September 20, 2009 That's very nice, but afaik C# does only support the SendKeys method. I need to send keystrokes to different (text control) windows outside of my application, e. g. CTRL + SHIFT + RIGHT which marks one word to the right. Those windows can be a Word document, a new email, a textbox within another application etc. And this has to work also if the regarding window is not the active (foreground) window and if another window has the same title. Therefore I need to address the window by it's handle. Link to comment Share on other sites More sharing options...
SueImWeb Posted September 20, 2009 Author Share Posted September 20, 2009 I got it...have to send the window's handle in hex format. Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 21, 2009 Share Posted September 21, 2009 I don't think you quite understand how AutoIt and C# work. AutoIt calls functions in the Windows API, which C# can also call. You managed to solve the problem though, so congratulations. Link to comment Share on other sites More sharing options...
SueImWeb Posted September 21, 2009 Author Share Posted September 21, 2009 (edited) I do understand that I am able to call API functions from C# too. What I primarily was looking for was an ability of sending keystrokes (combinations) to not active windows. Trying to find a solution I played with .NET SendKeys and API methods SendInput and PostMessage (with WM_KEYDOWN, WM_CHAR etc). But I had to end up with the information, that this is not possible because you can't simulate holding a key pressed respectivly simulate key combinations with WM_KEYDOWN. Besides SendInput and keybd_event are sent to the active window and WM_CHAR does only support ascii codes or ALT + 1 ascii key. So for the first I changed my application code to send messages only to active windows. Because I am less of time and using AutoItX for that is more comfortable than using API methods directly I implemented it. My next step is to learn how to register hotkeys. I hope WM_HOTKEY could be the solution for my problem. Any other idea? Sue Edited September 21, 2009 by SueImWeb Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 21, 2009 Share Posted September 21, 2009 You should look at PostMessageW. It's the Unicode version of PostMessage.And the function RegisterHotKey is what you need for hotkeys. 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