0

I want to use exceptions in my program. But my program have custom entrypoint and does not use CRT (C-runtime).

My program is simple as this:

    MessageBox(NULL, L"exception will be thrown", L"ok", MB_ICONEXCLAMATION | MB_OK);
    try {
      throw 123;
    } catch (...) {
      MessageBox(NULL, L"exception thrown", L"ok", MB_ICONEXCLAMATION | MB_OK);
    }

All works fine when I use standard entrypoint and CRT. But when I change EP of the program, it will crash with error 'Access violation' while calling function _CxxThrowException.

I've made a detailed screenshot of the crash: http://vs712.server4u.cz/exception.png

What is causing this error? Is there a workaround how to use exceptions without using CRT?

Thanks.

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
Peter
  • 580
  • 8
  • 22
  • _CxxThrowException is a CRT function. Your assertion that you don't use the CRT seems leaky and ultimately *very* unproductive. – Hans Passant Jul 05 '13 at 16:49
  • So basicly the only option is to write my own implementation of _CxxThrowException, right? – Peter Jul 05 '13 at 16:58

1 Answers1

-4

If your program is compiled by Visual C++. You SHOULD use CRT. You don't known what compiler do. Compiler can call any CRT function at anywhere in your code.

If you really don't want to use CRT. Then, use another compiler or another language like Assembly.

UltimaWeapon
  • 2,343
  • 18
  • 19
  • I've already solved this problem using SEH exceptions. "You don't known what compiler do. Compiler can call any CRT function at anywhere in your code." - What functions are you talking about? Give me some examples. – Peter Jul 11 '13 at 17:03
  • The example is if you enable `/GS` flag (its enabled by default). Visual C++ will call `__security_check_cookie` automatic at the end of every function to perform stack checking. – UltimaWeapon Jul 12 '13 at 05:18
  • I'm compiling with /GS- flag. – Peter Jul 12 '13 at 11:28
  • If you think you can handle all this problems. Then, do what you want to do. – UltimaWeapon Jul 12 '13 at 13:15