Question

When I execute this...

void CcrashDlg::OnBnClickedBtnCrash()
{
    char* ptr = NULL;
    *ptr = 1;
}

app just logs "Access Violation", and nothing happened.

How can I crash my MFC application? (visual studio 2010)

Was it helpful?

Solution

I believe the answer is hidden in the comments to the question, so I'm going to summarize it here - this is important stuff.

The full details are at this link: The case of the disappearing OnLoad exception – user-mode callback exceptions in x64.

Invalid operations that you would expect to crash the program don't crash in all circumstances. This includes many of the techniques outlined in the other answers.

The problem only occurs when you're using a 64-bit version of Windows and you're within a function that was called by the Windows kernel. In 32-bit versions of Windows, an exception or invalid operation could be caught from the code that called into the kernel, but in 64-bit versions of Windows this is impossible. Windows itself will catch the error at the user/kernel boundary, and ignore it! This was judged to be a better outcome than crashing the program every time, since the catch blocks that worked so well in 32-bit don't get a chance to handle the error anymore.

You should still be able to halt the process immediately using ExitProcess or TerminateProcess but I haven't tried them.

OTHER TIPS

just divide a number by zero,

int div = 1;
div--;
int cr = (any number)/div;

This is what I use to crash my app. I think it is same as yours. In release mode also it crashes.

*(int*)0 = 1;

Assert( NULL ) will crash your application in debug mode. I don't think you want to crash the release version but if so you can use Verifythere/both.

Other simple ways to cause crash is just use sprintfwith wrong formatting specifier for example feed a string when its expecting "%d".

  1. abort() works on release mode

  2. App crashes when compiled win64 platform on 64bit os.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top