davidm / luacom

Microsoft Component Object Model (COM) binding for Lua
http://lua-users.org/wiki/LuaCom
Other
116 stars 51 forks source link

StartMessageLoop only called once before blocking #2

Open TobyD opened 12 years ago

TobyD commented 12 years ago

There is a good chance that I am doing something wrong, but when trying to implement some event callbacks for a Lecroy Voyager M3i USB analyzer I am finding that my call to StartMessageLoop() from a lua script will block. I took a look at the luacom_StartMessageLoop code in luacom.cpp and see that it is calling GetMessage - a blocking call. I'm not sure what the solution should be...perhaps using PeekMessage (with the PM_REMOVE parameter to remove the message after processing) instead of GetMessage? Although then the loop would only run until there are no more messages to process. For now I created a new method luacom_NextMessage (shown below) and I call it everytime I want to querry the queue. That seems to be working. Am I doing something wrong? Is this a bug? Is there a better way to ensure events get handled?

int luacom_NextMessage(lua_State *L)
{
  MSG msg;
  if(PeekMessage(&msg, NULL, 0, 0, 1)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return 0;
}
wunoman commented 4 months ago

after start loop, you can send message to hwnd, and do what you want on message handler function.