| View previous topic :: View next topic |
| Author |
Message |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Wed Jun 20, 2007 8:53 am Post subject: SendMessage / PostMessage crashes AHK |
|
|
Have tried to isolate in more detail, but for now... hopefully this might be helpful...
Basically, 'intense' use of sendmessage/postmessage cause AHK crash. Various different events seem to possibly trigger the crash. Using a direct DLLCALL to sendmessage/postmessage bypasses the bug/crash, suggesting (?) may have to do with conversion of window id to handle (?).
The issue has not been simple to pin down, so in my DDE function have included the option to use the built-in SendMessage in place of DLL call.. to enable others option of examining/debuggnig the issue.
typical error message looks like:
| Quote: | AppName: autohotkey.exe AppVer: 1.0.46.15 ModName: user32.dll
ModVer: 5.1.2600.3099 Offset: 0004b64e |
Seems most often to crash for example, there is 'play' with the window(s) to which the sendmessage are directed. MAY be related to an internal coding issue of my ahk script.. such as if a bug is causing sending messages to a non-existent window. (although same code works without crashing if dll sendmessage is used directly...). Something about a target window being in focus, and then losing focus... or some such thing or ding... maybe.
ie.
| Code: | if !UseAHKMessages
DllCall("PostMessage", "UInt", DDEM_Server_ID, "UInt", WM_DDE_REQUEST , "UInt", DDEM_Client_ID , "UInt", CF_TEXT | hItem << 16)
else
PostMessage, WM_DDE_REQUEST, DDEM_Client_ID, CF_TEXT | hItem << 16,, ahk_id %DDEM_Server_ID%
|
produces different results. Script will *eventually* crash if UseAHKMessages is enabled. Notably, script is making the same posts (and sends), and works fine for a while... but eventually will crash if the AHK Messages are used vs. the direct dll call...
anyhow.. hope this was helpful. _________________ Joyce Jamce |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1337
|
Posted: Wed Jun 20, 2007 9:11 am Post subject: |
|
|
Always make sure you set when using AHK's built-in Post/SendMessage, even if used window handles:
| Code: | | DetectHiddenWindows, On |
|
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Wed Jun 20, 2007 10:26 am Post subject: |
|
|
@Sean, are you sure ? Sure does seem not to be necessary.. (ps. still getting the kinks out, but the function is looking *very* nice. Was only possible with your very lucid help & insight. Thanks!)
[did just try with detect hidden... same crash results].
note: With DDE to properly initiate a transaction we send a request GLOBALLY and we receive back the handle(s) to the server(s). _________________ Joyce Jamce |
|
| Back to top |
|
 |
Helpy Guest
|
Posted: Wed Jun 20, 2007 10:58 am Post subject: |
|
|
| Joy2DWorld wrote: | | @Sean, are you sure ? | Yes.
I saw experiment in communication between two scripts using WM_COPYDATA sent between the default hidden AHK windows, it worked only with this command. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1337
|
Posted: Wed Jun 20, 2007 11:24 am Post subject: |
|
|
| Helpy wrote: | | Joy2DWorld wrote: | | @Sean, are you sure ? | Yes.
I saw experiment in communication between two scripts using WM_COPYDATA sent between the default hidden AHK windows, it worked only with this command. |
I also noticed it from experiences. However, I always felt it confusing, or even contradictory with the documentation:
| Quote: | | To operate upon a control's HWND (window handle), leave the Control parameter blank and specify ahk_id %ControlHwnd% for the WinTitle parameter (this also works on hidden controls even when DetectHiddenWindows is Off). The HWND of a control is typically retrieved via ControlGet Hwnd, MouseGetPos, or DllCall. |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Jun 20, 2007 11:31 am Post subject: |
|
|
| I checked the code and don't see any obvious defects. If you can ever discover a simple script that reproduces the problem on any PC, I'll look into it further. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1337
|
Posted: Wed Jun 20, 2007 11:36 am Post subject: |
|
|
| Joy2DWorld wrote: | | [did just try with detect hidden... same crash results]. |
In this case, it must be added inside the function if necessary, as the function triggered via OnMessage() is always started as a new thread.
OTOH, I noticed that I also omitted 'DetectHiddenWindows On' from the functions, however, it worked flawlessly!
Now, I'm confused... Why did it worked in my usage?
Was it because 'DetectHiddenWindows On' is not necessary with window handles, or because the DDEServer was visible?
Last edited by Sean on Wed Jun 20, 2007 11:57 am; edited 1 time in total |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1337
|
Posted: Wed Jun 20, 2007 11:48 am Post subject: |
|
|
| Chris wrote: | | I checked the code and don't see any obvious defects. If you can ever discover a simple script that reproduces the problem on any PC, I'll look into it further. |
One of the examples is the BalloonTip script.
I replaced there all SendMessage with DllCall.
Now, if replace
| Code: | | DllCall("SendMessage", "Uint", hWnd, "Uint", 1028, "Uint", 0, "Uint", &ti) ; TTM_ADDTOOL |
with
| Code: | ;DetectHiddenWindows, On
SendMessage, 1028, 0, &ti,, ahk_id %hWnd% ; TTM_ADDTOOL |
then, there is no visible balloontip window.
However, after removing the comment from 'DetectHiddenWindows, On', it worked again.
Tested in XPSP2 Pro. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Jun 20, 2007 12:49 pm Post subject: |
|
|
| It could be because some windows unexpectedly vary in whether they have the WS_CHILD style. I've clarified the DetectHiddenWindows documentation to say, "Turning on DetectHiddenWindows is not necessary when accessing a control or child window via the ahk_id method or as the last-found-window. It is also not necessary when accessing GUI windows via Gui +LastFound." |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1337
|
Posted: Wed Jun 20, 2007 1:33 pm Post subject: |
|
|
| Chris wrote: | | It could be because some windows unexpectedly vary in whether they have the WS_CHILD style. |
That explains also why DDEMessage worked without 'DetectHiddenWindows On': I confirmed the DDEServer is created as a child window of DDEMom.
BTW, I wish at least ahk_id isn't governed by DetectHiddenWindows setting, although personally I don't like DetectHiddenWindows itself at all. |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Wed Jun 20, 2007 3:34 pm Post subject: |
|
|
| Quote: | | In this case, it must be added inside the function if necessary, as the function triggered via OnMessage() is always started as a new thread. |
soon hope to have worked around all the issues and you'll see ::> data can be accessed directly from main script ... sim. to ddeml but via AHK and with BATCH and multi connection capability... (only ack and data subs send msg from new 'thread', although that was just a 'style' choice to keep the functions complete as singular units.)... ie. DDE can be 'Pro-Active', not merely 're-active'... type thing.. _________________ Joyce Jamce |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Jun 20, 2007 5:54 pm Post subject: |
|
|
| Sean wrote: | | I wish at least ahk_id isn't governed by DetectHiddenWindows setting, although personally I don't like DetectHiddenWindows itself at all. | At one point, I wanted to change it that way; but now it might not be worth breaking existing scripts. In v2, it will probably be changed as you describe. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1337
|
Posted: Thu Jun 21, 2007 2:19 am Post subject: |
|
|
| Chris wrote: | | In v2, it will probably be changed as you describe. |
Good to know. Thanks for considering it. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1337
|
Posted: Thu Jun 21, 2007 2:20 am Post subject: |
|
|
| Joy2DWorld wrote: | | soon hope to have worked around all the issues and you'll see ::> data can be accessed directly from main script ... sim. to ddeml but via AHK and with BATCH and multi connection capability... (only ack and data subs send msg from new 'thread', although that was just a 'style' choice to keep the functions complete as singular units.)... ie. DDE can be 'Pro-Active', not merely 're-active'... type thing.. |
That will be very useful! Eagerly waiting. |
|
| Back to top |
|
 |
|