Message passing.
- Posted by Patrick Barnes <mrtrick at gmail.com> Nov 27, 2004
- 574 views
I'm trying to pass messages from 1 program to another... The sending procedure needs to return as soon as it's sent the message. The receiving function needs to be waiting until message A, or B or C is sent to it, then return with the message that was received (if another type of message is received, it'll be dispatched). This is what I thought would work, but nothing seems to be getting to the receiving program:
include dll.e include machine.e constant user32 = open_dll("user32") constant xRegisterWindowMessage = define_c_func(user32, "RegisterWindowMessageA", { C_LONG }, C_INT ) constant xGetMessage = define_c_func(user32, "GetMessageA", {C_POINTER,C_POINTER,C_UINT,C_UINT}, C_INT) constant xTranslateMessage = define_c_proc(user32, "TranslateMessage", {C_INT}) constant xDispatchMessage = define_c_proc(user32, "DispatchMessageA", {C_POINTER}) constant xPostMessage = define_c_proc(user32, "PostMessageA", {C_POINTER, C_UINT, C_LONG, C_LONG}) constant SIZEOF_MSG = 28 --Message communication: constant mem_msg = allocate(SIZEOF_MSG) global function waitForMessage( object types) atom ret, message_type if atom(types) then types = {types} end if while 1 do -- Get a message... ret = c_func( xGetMessage, { mem_msg, 0, 0, 0 } ) <----- It stops here... message_type = peek4u(mem_msg+4) --A quit message was received... if ret = 0 or ret = -1 then return -1 --One of the specified messages was received... elsif find(message_type, types) then return message_type --A different message was received. else c_proc( xTranslateMessage, { mem_msg } ) c_proc( xDispatchMessage, { mem_msg } ) end if end while end function global procedure PostMessage(atom hwnd, atom message) --Send a message to the hwnd process. --Returns immediately. c_proc( xPostMessage, {hwnd, message, 0, 0} ) end procedure
(the two routines are in different programs, just shown together here) Any ideas? -- MrTrick