PRB: Assert in Wincore.cpp with MFC in an NT ServiceID: Q164166
|
When you use a Visual C++ 4.x MFC application spawned from a NT service or as a NT service, an assertion may occur in Wincore.cpp. Specifically, it occurs on the following line in _AfxActivationWndProc():
LRESULT CALLBACK
_AfxActivationWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
WNDPROC oldWndProc = (WNDPROC)::GetProp(hWnd, szAfxOldWndProc);
ASSERT(oldWndProc != NULL); // <----- assert occurs here
.
.
.
}
The assertion occurs on line 385 with Visual C++ versions 4.2 and 4.2b, and
on line 384 with Visual C++ version 4.1.
MFC subclasses all non-MFC created windows to handle specific activation
issues. While subclassing a non-MFC created window, the old window
procedure is stored in the properties of the window. Logging off of an NT
session causes the atoms used to identify the properties to be destroyed
and the property cannot be retrieved. This causes the assertion to occur.
MFC was not designed for Windows NT services. As a result, if an MFC
application is spawned from a Windows NT service, minimized, and then a
user logs-off, then the assertion will occur.
Also keep in mind that there are other problems to consider when spawning
an MFC application from a service or as a service. The OnEndSession()
message handler for the main frame window closes out the CDocument object.
So the WM_ENDSESSION message must be handled to prevent this from
happening.
You can do one of the following things:
static const TCHAR szAfxOldWndProc[] = _T("AfxOldWndProc");
BOOL CALLBACK EnumProc( HWND hWnd, LPARAM lParam)
{
//check for property and unsubclass if necessary
WNDPROC oldWndProc = (WNDPROC)::GetProp(hWnd, szAfxOldWndProc);
if (oldWndProc!=NULL)
{
SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)oldWndProc);
RemoveProp(hWnd, szAfxOldWndProc);
}
return TRUE;
}
void CMainFrame::OnEndSession(BOOL bEnding)
{
// unsubclass the non-MFC windows which MFC has subclassed
DWORD dwProcessId;
DWORD dwThreadId= GetWindowThreadProcessId(m_hWnd,&dwProcessId);
EnumThreadWindows(dwThreadId, EnumProc,(LPARAM) dwThreadId);
}
Keywords : kbcode kbMFC KbUIDesign kbVC
Version : 4.00 4.10 4.20
Platform : NT WINDOWS
Issue type :
Last Reviewed: July 28, 1999