1. --!movie
  2. --!encoding=utf-8
  3.  
  4. global $
  5. global mx
  6.  
  7. ----------------------------------------
  8. --
  9. ----------------------------------------
  10. on startMovie
  11.     ok = consoleAttach()
  12.  
  13.     -- get command line
  14.     args = getCommandLineArgs()
  15.     if args.count<2 then
  16.         stdErr($.LF&"Usage: middleware <window title> <command>"&$.LF)
  17.         exitCode(1)
  18.     end if
  19.  
  20.     win_title = args[1]
  21.     cmd = args[2]
  22.  
  23.     -- load msg xtra
  24.     mx = xtra("Msg").new()
  25.  
  26.     -- find window handle of target projector
  27.     hwnd = mx.find_win("ImlWinCls", win_title)
  28.     if hwnd=0 then
  29.         stdErr($.LF&"Error: could not find window with title '"&win_title&"'"&$.LF)
  30.         exitCode(2)
  31.     end if
  32.  
  33.     -- send cmd (prepended with this middleware projector's window handle) as
  34.     -- WM_COPYDATA message to target projector
  35.     mx.send_data(hwnd, mx.stage_handle() && cmd)
  36.  
  37.     -- start waiting for the result (WM_COPYDATA = 74)
  38.     mx.msg_listen([74], VOID, #slotMsgReceived)
  39.  
  40.     -- TODO:
  41.     -- add timeout after which this exe quits even if no
  42.     -- WM_COPYDATA message was received from target projector
  43. end
  44.  
  45. --------------------------------------
  46. -- @callback
  47. --------------------------------------
  48. on slotMsgReceived (hwnd, msg, wParam, lParam, data, dwData)
  49.  
  50.     -- forward received result to caller (by printing it to STDOUT)
  51.     res = data.readRawString(data.length)
  52.     stdOut(res)
  53.  
  54.     -- exit
  55.     _player.quit() -- same as exitCode(0)
  56. end
  57.  
[raw code]