I have an MFC C++ program that occasionally crashes on an error exit for no apparent reason. My specific query is in the following:
In my overload of InitInstance() there are various checks, as well as setting up resources like events and semaphores. When a normal exit is requested by the user, there is an OnDestroy() message handler that closes everything out, including freeing resources, etc. That bit works fine.
The problem occurs when one of the checks in InitInstance() fails, and the function returns value 0 (causing a program exit). My question is this: In that event, is OnDestroy() automatically called to clean things up, or do I need to run it myself before exiting InitInstance?