Disable sending messages in handler

I am working on a Windows program that is completely single threaded and does not protect any data structure. However, the program uses the DirectShow API, which opens its own internal message dispatch, such as IVideoWindow :: put_Visible. Thus, the event handling function that calls the IVideoWindow :: put_Visible method enables other event handling functions to destroy their data.

Anyway, to prevent such messages from being sent to the API?

+1


a source to share


1 answer


The question is a little unclear to me. Are you talking about an API that introduces an internal message loop? Does this pose some kind of re-login problem for you? If so, then there are probably better ways to fix your problem. If the API introduces a modal loop, then there is undoubtedly a good reason and you should let it do it. (In your case, I'm assuming DirectShow is interacting with another COM object internally.) If written correctly, the modal loop will still send messages to other windows on the same thread.

Anyway, if you really want to do this, here's how:



PostQuitMessage( 0 ); // Signal quit to force the upcoming loop to exit
APIFunc(); // Enters modal loop internally
MSG msg;
PeekMessage( &msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE ); // Eat the next WM_QUIT

      

The last step is important. When a modal loop exits due to a WM_QUIT message, it should post its own exit message after it exits (so the application knows to exit). If you don't eat it, your app will exit.

0


a source







All Articles