--!movie
--!encoding=utf-8
global $
global mx
----------------------------------------
--
----------------------------------------
on startMovie
ok = consoleAttach()
-- get command line
args = getCommandLineArgs()
if args.count<2 then
stdErr($.LF&"Usage: middleware <window title> <command>"&$.LF)
exitCode(1)
end if
win_title = args[1]
cmd = args[2]
-- load msg xtra
mx = xtra("Msg").new()
-- find window handle of target projector
hwnd = mx.find_win("ImlWinCls", win_title)
if hwnd=0 then
stdErr($.LF&"Error: could not find window with title '"&win_title&"'"&$.LF)
exitCode(2)
end if
-- send cmd (prepended with this middleware projector's window handle) as
-- WM_COPYDATA message to target projector
mx.send_data(hwnd, mx.stage_handle() && cmd)
-- start waiting for the result (WM_COPYDATA = 74)
mx.msg_listen([74], VOID, #slotMsgReceived)
-- TODO:
-- add timeout after which this exe quits even if no
-- WM_COPYDATA message was received from target projector
end
--------------------------------------
-- @callback
--------------------------------------
on slotMsgReceived (hwnd, msg, wParam, lParam, data, dwData)
-- forward received result to caller (by printing it to STDOUT)
res = data.readRawString(data.length)
stdOut(res)
-- exit
_player.quit() -- same as exitCode(0)
end