Sign in to follow this  
Followers 0
SueImWeb

Can't get AutoItX to work using it by DLLImport (C#)

11 posts in this topic

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

Share this post


Link to post
Share on other sites



What type are you using for the string parameters? AutoItX was upgraded to Unicode, so your function prototypes will have to match.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Use UnmanagedType.LPWStr instead. LPStr is a single byte string, while LPWStr is a wide character string.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thank you very much ... that works. :D

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 by SueImWeb

Share this post


Link to post
Share on other sites

What exactly are you trying to do? I may be able to help you do it directly in C#.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I got it...have to send the window's handle in hex format.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by SueImWeb

Share this post


Link to post
Share on other sites

You should look at PostMessageW. It's the Unicode version of PostMessage.

And the function RegisterHotKey is what you need for hotkeys.

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