Sign in to follow this  
Followers 0
Spoonsx21

Getting handle from AU3_WinGetHandle

12 posts in this topic

Hello,

Let me start off by saying that AutoIt is amazing. I was going to try writing all of my program in the AutoIt scripting language, but it's too much of a hassle to learn a new language for a single program. So I decided to use AutoItX. I've had plenty of C++ experience, and I've messed around with Ogre for the last few weeks new. However, I haven't done much with the Windows API.

Anyways, that being said, the documentation for AutoItX is TERRIBLE. And normally, I wouldn't complain, but there are no other resources on this. And so few people have posted anything about this problem. For my other issues I've looked at the parallel function inside the AutoIt language, but I just can't figure out the issue now.

So, if somebody could explain my problem, I would be eternally greatful:

So AU3_WinGetHandle takes in 4 arguments, the title of the window handle we want, another argument I have no idea what it does, the LPWSTR that gets our handle, and the nBufSize.

I call AU3_WinGetHandle(TEXT("Untitled - "), TEXT(""), stringHere, 0);

And every time no matter what, I get a bad ptr error. I made the first input "Untitled - " because I launch notepad and I'm just testing it on a small program before I run it on my real program. Does it matter what type stringHere is? Does it need to be a different type for it to work? Should I be sending in something different for my first argument?

Does anyone know of a way to do this without AutoItX? And is that a better way to find the window handle? I really like using the library, but it's impossible to get information on how to use the function if the docs only have information on an alternate version of the function you're using (again though, I enjoy the library, and this is in no way meant to be me trashing auto it, I'm just frustrated).

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Well first off, nBufSize needs to be the size of your return buffer. 0 certainly isn't going to work...

Look in the AutoItX.chm help file. The main 'DLL Interface' heading has the basic info you seem to have missed.

Edited by wraithdu

Share this post


Link to post
Share on other sites

To get the handle without AutoItX, all you have to do is call EnumWindows. You pass a callback function pointer that is called for every top level window. It gives you the window handle and you can check the text to see if that is the window you want.

In AutoItX,

AU3_API void WINAPI AU3_WinGetHandle(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, LPWSTR szRetText, int nBufSize);

It actually returns the handle as text, if what I see here is correct. That doesn't really make a lot of sense.

You do need to correct the last parameter though. That 0 means your buffer has 0 spaces, so AutoItX doesn't give you anything. The last parameter is the size of the buffer for szRetText.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You guys are a lifesaver, thank you! I'll chock that one up to my inexperience with the Win API, not AutoItX.

Thanks again.

-Paul

P.S. What would be a good buffer size? Is the buffer size fixed for any windows handle?

Edited by Spoonsx21

Share this post


Link to post
Share on other sites

A window handle is a 32-bit integer, so depending on whether AutoItX is returning '12345678' or 0x12345678', you could need up to 40 bits (10 bytes). Just test it out with something bigger and see what you need.

Share this post


Link to post
Share on other sites

Wrong. A window handle is an integer yes, but it depends on the operating system. 32 bit Windows uses 32 bit handles. 64 bit Windows uses 64 bit handles.

As for a string buffer, it's easy to allocate 100 bytes. It's not huge and probably not too small.

Share this post


Link to post
Share on other sites

Good point. I wasn't thinking about 64-bit.

Share this post


Link to post
Share on other sites

Good point. I wasn't thinking about 64-bit.

I figured that's all it was. :)

Share this post


Link to post
Share on other sites

Hi,

I trying to use AutoItX in Java using JNA

I want to use this function

public void AU3_WinGetHandle(WString szTitle, WString szText, byte[] szRetText, int nBufSize);

But what is szRetText and nBufSize ? Is szRetText in hex ? The value return szRetText don't make sense. How can I retrieve its winHandle value just like in AutoIt ?

thx

Share this post


Link to post
Share on other sites

Where did you get that function declaration? That's not what's in the header files included with AutoIt.

Either way, szRetText is a pointer to the text buffer you want to receive the handle, and nBufSize is the size of the buffer.

Share this post


Link to post
Share on other sites

wraithdu,

I obtain that from

http://www.autoitscript.com/forum/index.php?showtopic=53013

"Either way, szRetText is a pointer to the text buffer you want to receive the handle, and nBufSize is the size of the buffer."

Why should AU3_WinGetHandle in AutoItX not design to return the value of window handle just like in AutoIt ? Why expose szRetText and nBufSize as argument ?

Even the WinGetText and WinGetTitle etc have szRetText and nBufSize . These arguments are not present in AutoIt, only in AutoIt3. So what value is returned from szRetText and how can I convert it to Window Handle which is integer value.

Share this post


Link to post
Share on other sites

The JNA library you are using is a thin wrapper around AutoItX3.dll and that is the syntax of the native C function calls. If you don't understand Java or C, well, sorry but I'm not here to teach you that. Suffice to say that is the way Java and C work.

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