Quote:
There's no need to subclass the window anyway.
Ah, yes.... there is no need for this in this case, thx for the note.
Quote:
I'm a noob but very interested by IPC. Can you please give us an example ? Thanks by advance.
This is a sample of server and client. Client asks for some information that require some time to be calculated (like db access). Client can ask for new information again, before server finishes previous one. Server buffers requests, and sends them back as soon as it calculates. Ports are used as transaction IDs so this can work ok for 2^32 transactions.
This approach was needed because IPC doesn't use PostMessage to send WM_COPYDATA, but SendMessage which waits. PostMessage can't be used with WM_COPYDATA.
Server.ahk
Code:
#SingleInstance, off ;allow multiple instances
target := "Klijent"
Gui, +LastFound +AlwaysOnTop
hScript := WinExist()
Gui, Font, s8
Gui, Add, ListBox,xm w350 h300 vMyLB,
Gui, Show, x600 AutoSize
IPC_OnMessage("OnMessage")
return
OnMessage:
GuiControl, , MyLB, %IPC_Port% : %IPC_Message%
buf .= IPC_PORT " "
aMessage_%IPC_PORT% := IPC_Message
if !Timer
{
SetTimer, DBGet, -50
Timer := true
}
return
DBGet:
loop
{
j := InStr(buf, " "), port := SubStr(buf, 1, j-1), buf := SubStr(buf, j+1)
msg := aMessage_%port%
data := SQLGetData(msg)
IPC_Send(WinExist(target), data, port)
IfEqual, buf,, break
}
Timer := false
return
SQLGetData(msg) {
sleep 5000
return "data for: " msg
}
GuiClose:
exitapp
return
#include IPC.ahk
Klijent.ahkCode:
#SingleInstance, off ;allow multiple instances
target := "Server"
Gui, +LastFound +AlwaysOnTop
hScript := WinExist()
Gui, Font, s10
Gui, Add, Edit, vMyMsg w310 , select * from table
Gui, Font, s8
Gui, Add, Button, x+5 gOnSend , Send
Gui, Add, ListBox,xm w350 h300 vMyLB,
Gui, Show, x200 AutoSize
port := 0
IPC_OnMessage("OnMessage")
return
OnMessage:
GuiControl, , MyLB, %IPC_Port% : %IPC_Message%
return
OnSend:
Gui, Submit, NoHide
port++
res := IPC_Send( WinExist( target ), MyMsg, port)
return
GuiClose:
exitapp
return
#include IPC.ahk