Re: Closing documents caused random crash in ActiveX server
application
A workaround seems to prevent the crash. Can anyone see a clue to
properly fix the seemingly "synchronization error"?
Following is the essence of my workaround. That's bypassing
CWinApp::OnIdle call if lCount is zero. Therefore avoids the
CWindThread::OnIdle where the crash would be observed. I set the
debug break point inside the line of if( lCount != 0 ). However, the
breakpoint never hits. It doesn't seem that the lCount is ever of
zero.
If I am going ahead of the workaround, is my OnIdle method below
sufficient?
void CMyOLEServerApp::OnIdle(LONG lCount)
{
if (lCount == 0)
{
//copied here from CWinThread::OnIdle to update mainframe
CWnd* pMainWnd = m_pMainWnd;
if (pMainWnd != NULL && pMainWnd->m_hWnd != NULL && pMainWnd-
IsWindowVisible())
{
AfxCallWndProc(pMainWnd, pMainWnd->m_hWnd,
WM_IDLEUPDATECMDUI, (WPARAM)TRUE, 0);
pMainWnd->SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE,
0, TRUE, TRUE);
}
DWORD nMinMbFree;
GetMinFreeRAMinMB(nMinMbFree);
MEMORYSTATUS ms;
ms.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&ms);
DWORD dwOldFree = 0xffffffff;
DWORD dwMinBytes = nMinMbFree;
dwMinBytes *= 1024;
dwMinBytes *= 1024;
while ((ms.dwAvailPageFile < dwMinBytes) && (dwOldFree !=
ms.dwAvailPageFile))
{
if (m_pMainWnd != NULL)
{
(m_pMainWnd)->SendMessageToDescendants(WM_COMMAND,
ID_PRIV_MEMORY);
}
dwOldFree = ms.dwAvailPageFile;
GlobalMemoryStatus(&ms);
}
}
BOOL bRet = FALSE;
if( lCount != 0 )
{
bRet = CWinApp::OnIdle(lCount);
}
return bRet;
}