Closing an application safely

Posted on 2009-04-18
Last Modified: 2013-11-20

I am doing some checks in the InitInstance of an SDI application. If certain conditions are not met e.g. certain files to be loaded, cannot be found the application needs to shut down. I have done this by using exit(0) whenever I need to close the application.

This works but I tend to get memory leaks and, when I'm using the debugger to check the code, the application closes but it still appears to be in memory in Visual Studio so I have to use Stop Debugging to close it down (even though the application doesn't appear on-screen).

Can anybody give me advice on how to close an SDI application without having these problems?

Question by:IssacJones
    LVL 43

    Accepted Solution

    AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);

    Author Closing Comment

    Cheers Andy!

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now