Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reason of assertion failure: CWinThread::Pumpmessage() called when not permitted.

583 views
Skip to first unread message

deepak k jain

unread,
Mar 13, 2002, 4:21:01 PM3/13/02
to
hi all,
i just now posted a msg asking the reason of following assertion in
mfc debug:
CWinThread::Pumpmessage() called when not permitted.

i couldn't find any satisfactory answer in already posted threads.
meanwhile i figured it out myself, and am posting it, may be it could
help somebody...

i went through mfc source code. it showed that when ::GetMessage()
function call in CWinThread::PumpMessage() fails, then it increments
some variable which, in the next call to PumpMessage(), which itself
is repeteadly called from CWinThread::Run(). here is the very code of
CWinThread::PumpMessage() which causes this assertion error:

if (!::GetMessage(&m_msgCur, NULL, NULL, NULL))
{
#ifdef _DEBUG
if (afxTraceFlags & traceAppMsg)
TRACE0("CWinThread::PumpMessage - Received WM_QUIT.\n");
m_nDisablePumpCount++; // application must die
// Note: prevents calling message loop things in 'ExitInstance'
// will never be decremented
#endif
return FALSE;
}


on checking documentation for ::GetMessage(), it shows that it returns
NULL when there is WM_QUIT message in the message queue.
now, line that was causing error in my case: (your case may be
different, but somehow you too are causing the application to quit,
while still working on it, like i was still trying to show a dialog
box.)

(this is part of my CAsyncSocket-derived class code)
CMySocket::OnConnect( int nErrorCode)
{
...
case WSAECONNREFUSED:
AfxMessageBox("Please check whether the server is
running.\n",MB_ICONSTOP);
AfxPostQuitMessage(0); //this caused the assertion error
break;
...
}


bye,
deepak

Joseph M. Newcomer

unread,
Mar 13, 2002, 9:45:54 PM3/13/02
to
Sounds right to me. Once WM_QUIT is received, the message pump is supposed to be dead, so
calling it again is clearly an error. You are probably using a UI thread to handle a
socket connection; note that WinSock might be trying still to handle messages. What is the
traceback when this occurs?
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm

0 new messages