Problem with message dispatching in thread
From: Magnus Oskarsson (magnus.oskarsson_at_enera.se)
Date: 01/26/04
- Next message: Mustafa Korkmaz: "Re: how can we notice that the web-cam is installed or not?"
- Previous message: Daniel J. Wojcik: "Re: how can we notice that the web-cam is installed or not?"
- Next in thread: Peter Below (TeamB): "Re: Problem with message dispatching in thread"
- Reply: Peter Below (TeamB): "Re: Problem with message dispatching in thread"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 26 Jan 2004 14:03:48 +0100
I have a thread that spends most of its time waiting for various events
and/or input in its message queue. Support for the latter was added so that
it would be possible to create objects such as timers in code executed in
this thread. It turns out that the thread receives a number of messages even
when no objects such as timers are created, and that dispatching these
messages occasionally causes an access violation. The messages in these
cases were WM_DEVICECHANGE with wParam 7 and lParam 0. The key code looks
like this:
PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE); {initialize the message queue}
...
SignaledObject := MsgWaitForMultipleObjects(EventCount, HandleArray, False,
INFINITE, QS_ALLINPUT);
case SignaledObject of
...
{cases for various signaled synchronization objects}
...
else {input in the message queue}
while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
DispatchMessage(Msg);
end;
What is it that is wrong with this code? I have tried a fix that replaces
the DispatchMessage row with:
if OneOfMyExpectedMessages(Msg.message) then
DispatchMessage(Msg);
where the added function returns True only for a few messages, e.g.
WM_TIMER. This fix removes the AVs, but I would like to know if I introduce
any new problems by not dispatching all messages.
Regards
Magnus Oskarsson
- Next message: Mustafa Korkmaz: "Re: how can we notice that the web-cam is installed or not?"
- Previous message: Daniel J. Wojcik: "Re: how can we notice that the web-cam is installed or not?"
- Next in thread: Peter Below (TeamB): "Re: Problem with message dispatching in thread"
- Reply: Peter Below (TeamB): "Re: Problem with message dispatching in thread"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]