Reputation: 591
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)
Upvotes: 3
Views: 544
Reputation: 308176
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.
Upvotes: 3
Reputation: 540
just divide a number by zero,
int div = 1;
div--;
int cr = (any number)/div;
Upvotes: 2
Reputation: 591
abort() works on release mode
App crashes when compiled win64 platform on 64bit os.
Upvotes: 0
Reputation: 12227
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 Verify
there/both.
Other simple ways to cause crash is just use sprintf
with wrong formatting specifier for example feed a string when its expecting "%d".
Upvotes: 0
Reputation: 6849
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;
Upvotes: 0