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)
}