Spoonsx21 Posted October 2, 2009 Share Posted October 2, 2009 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). Link to comment Share on other sites More sharing options...
wraithdu Posted October 2, 2009 Share Posted October 2, 2009 (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 October 2, 2009 by wraithdu Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 2, 2009 Share Posted October 2, 2009 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. Link to comment Share on other sites More sharing options...
Spoonsx21 Posted October 3, 2009 Author Share Posted October 3, 2009 (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 October 3, 2009 by Spoonsx21 Link to comment Share on other sites More sharing options...
wraithdu Posted October 3, 2009 Share Posted October 3, 2009 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. Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 4, 2009 Share Posted October 4, 2009 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. Link to comment Share on other sites More sharing options...
wraithdu Posted October 4, 2009 Share Posted October 4, 2009 Good point. I wasn't thinking about 64-bit. Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 5, 2009 Share Posted October 5, 2009 Good point. I wasn't thinking about 64-bit.I figured that's all it was. Link to comment Share on other sites More sharing options...
geekycoder Posted January 15, 2010 Share Posted January 15, 2010 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 Link to comment Share on other sites More sharing options...
wraithdu Posted January 15, 2010 Share Posted January 15, 2010 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. Link to comment Share on other sites More sharing options...
geekycoder Posted January 15, 2010 Share Posted January 15, 2010 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. Link to comment Share on other sites More sharing options...
wraithdu Posted January 15, 2010 Share Posted January 15, 2010 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. 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