> I am encountering a very strange error:
> Openning a Visual C++/Win32 Console project with mfc support, writing a simple Sleep(5000) function in the main and running the app in Debug mode (default settings). while closing the app in the middle of execution (click on the close
window button) i am getting the following error:
> "Unhandled exception at 0x7c29ed41 (mfc71d.dll) in test2.exe: 0xC0000005: Access violation reading location 0xf78b78e8."
>
[quoted text clipped - 3 lines]
>
> Running Visual Studio.NET 7.1.3088, .NET Framework 1.1.4322 SP1, on Windows2000 Professional, SP4
When you click Close button, the default handler for the event calls ExitProcess,
thus triggering MFC cleanup. The problem is that the system starts a new thread
to call the handler, and therefore the cleanup is made on that thread, not on
the main thread (which is killed by ExitProcess by that time).
The solution is to register your own handler for Close, Ctrl-C and Ctrl-Break events
(using SetConsoleCtrlHandler function), handle these events and ask your main thread
to exit cleanly.
Regards,
Oleg