dpaynebrown Posted September 15, 2007 Posted September 15, 2007 Creating solutions to problems with AutoIt has been a great experience. AutoIt handles just about every application programming task that we need, including Regular Expressions, the DOM for Excel and IE, Registry management, and so forth. And because its syntax is similar to VBScript, the learning curve has been low.But we have a question.Currently we have an AutoIt program that contains several simple functions which are called by an external application. We do it like this:AutoIt loops waiting for a value, which is a function name string, to be placed in a Registry key by that external program. It reads the string, does the function, writes the answer out to another Registry key, sets the key back to a blank string, and then goes back to looping and waiting.Is there a better way to do this? Is there a better way to have AutoIt fire off an internal function that the external application needs the results from?One of these external applications can make use of the PostMessage API call (but not SendMessage). Furthermore, the message type can be an offset from WM_USER, an offset from WM_APP, or a RegisterWindowMessage.Bear in mind that we know very little about Windows messaging and API calls, but I assume that we would need to compile the AutoIt app into an executable in order to know "what" to send the PostMessage message to. Yes? No? If we are way off base, then don't hesitate to say so!If there is a better way, if we are on the right track, then any help or example would be peachy-keen.
PsaltyDS Posted September 15, 2007 Posted September 15, 2007 Search this forum for WM_CopyData. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
dpaynebrown Posted September 15, 2007 Author Posted September 15, 2007 Search this forum for WM_CopyDataYes, I was looking at some of those examples before. However, I was not refering to two AutoIt scripts communicating with each other, but rather an external, non-AutoIt application having an AutoIt script fire specific functions.The only API call that the external app has available is the PostMessage command. So I was wondering if it could, or should, be used to call functions within an AutoIt Script. if so, how?The external application's message type to send can be either an offset from WM_USER, an offset from WM_APP, or a RegisterWindowMessage. I assume we would want to use the latter, but how? Furthermore, do we, or can we, use the WParam and LParam fields in the message to tell AutoIt which function to fire? If so, how?It may be that what we are doing now is as good as it can ever get, we simply do not know, but I thought someone here might be able to tell us.
BobK Posted September 15, 2007 Posted September 15, 2007 (edited) Is there any reason your external application can't use an AutoIt object or just call autoit functions from the dll? If it can, then it is an easy matter to exchange press buttons and exchange data between the two programs. Another way is to have the AutoIt program monitor an editbox in the external application (it can be an invisible edit box), and get its instructions as to what to do from that box and return data to that box or another one. Edited September 15, 2007 by BobK
dpaynebrown Posted September 15, 2007 Author Posted September 15, 2007 Is there any reason your external application can't use an AutoIt object or just call autoit functions from the dll?If you are referring to AutoItX, I can't do anything like CreateObject( "AutoItX3.Control" ). It's not a programming-type app. But even if I could call a DLL, how would I convert the au3 file containing all the functions we created into a dll file?Another way is to have the AutoIt program monitor an editbox in the external application (it can be an invisible edit box), and get its instructions as to what to do from that box and return data to that box or another one.Well, it's not a programming-type app, so I can't add any controls to it.
Siao Posted September 16, 2007 Posted September 16, 2007 You can send stuff using wParam and lParam of PostMessage, but that would be numbers or pointers, as it basically 2 dwords at your disposal. Quick example, run these two scripts, should be pretty self-explanatory: #include <GUIConstants.au3> $gui = GUICreate("Sender", 300, 150) $btn = GUICtrlCreateButton("Send", 100, 50, 100, 50) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btn sender() EndSwitch WEnd Func sender() If WinExists("Receiver") Then $hwnd = WinGetHandle("Receiver") DllCall("user32.dll", "int", "PostMessage", "hwnd", $hwnd, "uint", $WM_USER, "uint", 1, "uint", 2) Else MsgBox(0,"","Receiver window not found") EndIf EndFuncoÝ÷ Ù«¢+Ø¥¹±Õ±ÐíU% ½¹ÍѹÑ̹ÔÌÐì((ÀÌØíÕ¤ôU% ÉÑ ÅÕ½ÐíI¥ÙÈÅÕ½Ðì°ÌÀÀ°ÄÔÀ¤)U%I¥ÍÑÉ5Í ÀÌØí]5}UMH°ÅÕ½Ðí=¹}]5}UMHÅÕ½Ðì¤)U%MÑMÑÑ ¤()]¡¥±U%Ñ5Í ¤±ÐìÐìÀÌØíU%}Y9Q} 1=M)]¹()Õ¹=¹}]5}UMH ÀÌØí¡]¹°ÀÌØí5ͰÀÌØíÝAÉ´°ÀÌØí±AÉ´¤(%5Í ½à À°ÅÕ½Ðíå¼Ý½Ñ̵ÍÍÌÌìÅÕ½Ðì°ÅÕ½Ðí5ÍôÁàÅÕ½ÐìµÀì!à ÀÌØí5ͤµÀì HµÀì|($$$$$$$$$ÅÕ½ÐíÝAÉ´ôÅÕ½ÐìµÀìÀÌØíÝAÉ´µÀì HµÀì|($$$$$$$$$ÅÕ½Ðí±AÉ´ôÅÕ½ÐìµÀìÀÌØí±AÉ´¤)¹Õ¹ The question is, if that external app is capable of creating some kind of struct to keep that string you wanna pass, and send that pointer. Or maybe, if 8 bytes is enough for your message "be smart, drink your wine"
dpaynebrown Posted September 17, 2007 Author Posted September 17, 2007 Siao -Thanks. Your examples were spot on. They worked to perfection. I was able to post a message from the external app to the "receiver" script flawlessly.The question is, if that external app is capable of creating some kind of struct to keep that string you wanna pass, and send that pointer. Or maybe, if 8 bytes is enough for your messageNo, the external app does not have the ability to create a structure and generate a pointer to it, however, I can use the LParam and WParam as indexes to an array(s) of function names. That will work very well. Very well, indeed.Oh, and thanks to PsaltyDS and BobK for your input, too. They've certainly given us some ideas we can use on other projects!
Moderators SmOke_N Posted September 17, 2007 Moderators Posted September 17, 2007 I'm curious... is there any particular reason for using PostMessage versus SendMessage (other than the obvious of not waiting until the 2nd app responds that it has received the information)? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
dpaynebrown Posted September 17, 2007 Author Posted September 17, 2007 I'm curious... is there any particular reason for using PostMessage versus SendMessage (other than the obvious of not waiting until the 2nd app responds that it has received the information)?It's not a programming-type app and the only outside link it has is PostMessage in the form of a user input menu (which message to post, which handle to post it to, LParam, WParam). Heck, I'm not sure why it has that, unless the developer had intentions that were never carried through. SendMessage would have been nice, though!
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