AutoHotkey Community

It is currently May 26th, 2012, 10:09 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: October 20th, 2009, 12:35 am 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
Hi.

I have 2 scripts that communicate with each one with onmessage/sendmessage functions. They pass data with 0x4a message (WM_COPYDATA). When on the first script a tooltip is displayed, first script ignore messages from second script.

Isn't this a bug?

[Moderator's note: Moved topic from Bug Reports to Ask for Help.]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 4:54 am 
Most likely not, but we can't know unless you post code.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 10:35 am 
i run across the same problem(without solving it), check this post: http://www.autohotkey.com/forum/topic31673.html

so here is a demo for this problem:
Sender
Code:
;Sender-Script
RecPID := 1596 ;change this according to the MsgBox in the Receiver-Script
Message := 1111
return
^L::
Message += 1
result := Send_WM_COPYDATA(Message, RecPID)
MsgBox, %result%     
return

Send_WM_COPYDATA(ByRef Message, ByRef RecPID)
{
    VarSetCapacity(CopyDataStruct, 12, 0)
    NumPut(StrLen(Message) + 1, CopyDataStruct, 4)
    NumPut(&Message, CopyDataStruct, 8)
    Prev_DetectHiddenWindows := A_DetectHiddenWindows
    Prev_TitleMatchMode := A_TitleMatchMode
    DetectHiddenWindows On
    SetTitleMatchMode 2
    SendMessage, 0x4a, 0, &CopyDataStruct,, ahk_PID%RecPID%
    DetectHiddenWindows %Prev_DetectHiddenWindows%
    SetTitleMatchMode %Prev_TitleMatchMode%
    return ErrorLevel  ;
}


Receiver
Code:
;Receiver-Script
PID := DllCall("GetCurrentProcessId")
OnMessage(0x4a, "Receive_WM_COPYDATA")
MsgBox, RecPID := %PID%
Tooltip, Waiting
return

Receive_WM_COPYDATA(wParam, lParam)
{
   global BCCCopyOfData
    lpDataAddress := lParam + 8
    lpData := 0
    Loop 4
    {
        lpData := lpData | (*lpDataAddress << 8 * (A_Index - 1))
        lpDataAddress += 1
    }
    DataLength := DllCall("lstrlen", UInt, lpData)
    if DataLength <= 0
        ToolTip %A_ScriptName%`nA blank string was received or there was an error.
    else
    {
        VarSetCapacity(CopyOfData, DataLength)
        DllCall("lstrcpy", "str", CopyOfData, "uint", lpData)
        BCCCopyOfData := CopyOfData
        SetTimer, DoTooltip, -1000
    }
    return true
}

DoTooltip:
   ToolTip %A_ScriptName%`nReceived the following string:`n%BCCCopyOfData%
; sleep, 1000
; Tooltip
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 11:09 am 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
Thanks Z_Gecko, and sorry for double-posting.

I did some tests and I think this problem appear when "ahk_PID" is specified in SendMessage. When I specify "ahk_class", and not "ahk_PID", the problem doesn't appear.

In my script (is too long and complex to be posted), a tooltip is refreshed every second, and the problem still remain.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 12:16 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
That makes sense. If you use only ahk_pid, you are specifying "any window in that process." I think that usually means the top-most window in that process; i.e. the tooltip. I suppose the tooltip handles the message (or simply passes it to DefWindowProc) without allowing AutoHotkey a chance to intercept it. There shouldn't be any problem if you specify both ahk_class AutoHotkey and ahk_pid.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 1:50 pm 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
Lexikos wrote:
That makes sense. If you use only ahk_pid, you are specifying "any window in that process." I think that usually means the top-most window in that process; i.e. the tooltip. I suppose the tooltip handles the message (or simply passes it to DefWindowProc) without allowing AutoHotkey a chance to intercept it. There shouldn't be any problem if you specify both ahk_class AutoHotkey and ahk_pid.


I thought that too but, how to specify both ahk_class and ahk_pid? ;D I tried but never worked...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 4:19 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Thanks Lexikos, I had that problem as well, looks like it works as it should :)
Code:
SendMessage, 0x4a, 0, &CopyDataStruct,, ahk_PID %RecPID% ahk_class AutoHotkey

Test
Code:
;Receiver-Script
Receiver=
(
OnMessage(0x4a, "Receive_WM_COPYDATA")
Tooltip, Waiting
return

Receive_WM_COPYDATA(wParam, lParam)
{
   global BCCCopyOfData
    lpDataAddress := lParam + 8
    lpData := 0
    Loop 4
    {
        lpData := lpData | (*lpDataAddress << 8 * (A_Index - 1))
        lpDataAddress += 1
    }
    DataLength := DllCall("lstrlen", UInt, lpData)
    if DataLength <= 0
        ToolTip `%A_ScriptName`%``nA blank string was received or there was an error.
    else
    {
        VarSetCapacity(CopyOfData, DataLength)
        DllCall("lstrcpy", "str", CopyOfData, "uint", lpData)
        BCCCopyOfData := CopyOfData
        SetTimer, DoTooltip, -1000
    }
    return true
}

DoTooltip:
   ToolTip `%A_ScriptName`%``nReceived the following string:``n`%BCCCopyOfData`%
return
)



PID:=RunTempScript(Receiver,"Receiver")


;Sender-Script
Sender=
(
RecPID = %PID%
Message := 1111
Gosub, ^L
return
^L::
Message += 1
result := Send_WM_COPYDATA(Message, RecPID)
MsgBox, `%result`%     
return

Send_WM_COPYDATA(ByRef Message, ByRef RecPID)
{
    VarSetCapacity(CopyDataStruct, 12, 0)
    NumPut(StrLen(Message) + 1, CopyDataStruct, 4)
    NumPut(&Message, CopyDataStruct, 8)
    Prev_DetectHiddenWindows := A_DetectHiddenWindows
    Prev_TitleMatchMode := A_TitleMatchMode
    DetectHiddenWindows On
    SetTitleMatchMode 2
    SendMessage, 0x4a, 0, &CopyDataStruct,, ahk_PID `%RecPID`% ahk_class AutoHotkey
    DetectHiddenWindows `%Prev_DetectHiddenWindows`%
    SetTitleMatchMode `%Prev_TitleMatchMode`%
    return ErrorLevel  ;
}
Return
)

RunTempScript(Sender,"Sender")

ExitApp


RunTempScript(TempScript, name="")
{
   global #__AHK_EXE_
   If Name =
      #__PIPE_NAME_ := A_TickCount
   Else
      #__PIPE_NAME_ := name
   #__PIPE_GA_ := CreateNamedPipe(#__PIPE_NAME_, 2)
   #__PIPE_    := CreateNamedPipe(#__PIPE_NAME_, 2)
   if (#__PIPE_=-1 or #__PIPE_GA_=-1) {
      MsgBox CreateNamedPipe failed.
      Return
   }
   Run, %A_AhkPath% "\\.\pipe\%#__PIPE_NAME_%",,UseErrorLevel HIDE, PID
   If ErrorLevel
      MsgBox, 262144, ERROR,% "Could not open file:`n" #__AHK_EXE_ """\\.\pipe\" #__PIPE_NAME_ """"
   DllCall("ConnectNamedPipe","uint",#__PIPE_GA_,"uint",0)
   DllCall("CloseHandle","uint",#__PIPE_GA_)
   DllCall("ConnectNamedPipe","uint",#__PIPE_,"uint",0)
   script := chr(239) . chr(187) . chr(191) . TempScript
   if !DllCall("WriteFile","uint",#__PIPE_,"str",script,"uint",StrLen(script)+1,"uint*",0,"uint",0)
      MsgBox WriteFile failed: %ErrorLevel%/%A_LastError%
   DllCall("CloseHandle","uint",#__PIPE_)
   Return PID
}

CreateNamedPipe(Name, OpenMode=3, PipeMode=0, MaxInstances=255) {
   return DllCall("CreateNamedPipe","str","\\.\pipe\" Name,"uint",OpenMode
      ,"uint",PipeMode,"uint",MaxInstances,"uint",0,"uint",0,"uint",0,"uint",0)
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 4:53 pm 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
HotKeyIt wrote:
Code:
SendMessage, 0x4a, 0, &CopyDataStruct,, ahk_PID %RecPID% ahk_class AutoHotkey


I tried but it doesn't work to me...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 5:26 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Have you tried my example test?

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 5:58 pm 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
No, I haven't.
I tried this
Code:
SendMessage, 0x4a, 1, &CopyDataStruct,, ahk_PID %param1% ahk_class AutoHotKey

but the script doesn't receive anything without tooltip too.

I'll find a solution, thanks anyway :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 8:34 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Kai wrote:
Code:
SendMessage, 0x4a, 1, &CopyDataStruct,, ahk_PID %param1% ahk_class AutoHotKey

Does this make any difference?

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 20th, 2009, 11:18 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Window classes are case-sensitive. "ahk_class AutoHotKey" != "ahk_class AutoHotkey"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2009, 12:41 am 
Lexikos wrote:
Window classes are case-sensitive. "ahk_class AutoHotKey" != "ahk_class AutoHotkey"

...hahaha... :lol: ...like I've been saying...lowercase k people!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2009, 1:49 pm 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
LOL, unbelievable! XD

Thanks guys :P


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hyper_, JSLover, Leef_me, oldbrother, patgenn123 and 61 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group