Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to crash my mfc application

Tags:

visual-c++

mfc

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)

like image 683
chaeyk Avatar asked May 06 '26 20:05

chaeyk


1 Answers

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.

like image 191
Mark Ransom Avatar answered May 09 '26 14:05

Mark Ransom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!