C++ exception warnings in atl project

Started by
3 comments, last by kamrann 21 years, 9 months ago
I''m just starting out with COM and ATL, using the ATL COM app wizard in VC++6. As soon as I started including stl headers I got a load of the following warnings: warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify -GX They go away if I check Enable Exception Handling in project settings, but I was wondering why this was unchecked by default in this type of project. Can I not have this enabled when writing COM code? If not, is it safe to ignore the warnings? While I''m asking, can anyone think of a reason why in this type of project I might get a linker error: unresolved external : _main ??? This happened only when I tried to build in release mode - I hadn''t altered any project settings. Thanks Cameron
Advertisement
quote:Original post by kamrann
They go away if I check Enable Exception Handling in project settings, but I was wondering why this was unchecked by default in this type of project.

Because COM has "funny" exception semantics. There''s no ABI for C++ exceptions, so you can''t throw C++ exceptions across execution contexts. If you have exceptions enabled, ensure you deal with them within the scope of the component.
quote:
Can I not have this enabled when writing COM code? If not, is it safe to ignore the warnings?

Yes you can have it enabled. Don''t ignore the warnings, turn exceptions on and deal with the exception safety issues.
quote:
While I''m asking, can anyone think of a reason why in this type of project I might get a linker error:
unresolved external : _main ???

Not entirely sure. If you can figure out why your project thinks it has a symbol to fix-up called _main, then you can probably find your answer. Try grep''ping for the symbol in the source.
quote:Original post by kamrann
While I''m asking, can anyone think of a reason why in this type of project I might get a linker error:
unresolved external : _main ???
This happened only when I tried to build in release mode - I hadn''t altered any project settings.

search for info on _ATL_MIN_CRT. what happens is ATL by default sets up the project to not use CRT startup code in release mode, and you sre using a CRT function (memmove and similar pop up most often) that requires that code, resulting in unresolved _main. You can either fix your code, replacing CRT calls with Win32 alternatives, or remove _ATL_MIN_CRT and use the CRT startup code.

avoiding that code produces smaller exes that start faster, in case you''re wondering.

---
Come to #directxdev IRC channel on AfterNET
Thanks for the help.
I''ll have to look into exception handling, since I''ve never actually done it before in c++. And I''ll have a look tomorrow to see what crt functions I''m using and if I need them.

The problem with posting questions about COM seems to be that people assume you''re a pro and know what you''re doing, which I''m not and don''t. SabreMan, it probably won''t be necessary here since I think you didn''t realise that the _main symbol was probably the main function for a console app, but what is grep''ing anyway?

Cheers
Cameron
quote:search for info on _ATL_MIN_CRT. what happens is ATL by default sets up the project to not use CRT startup code in release mode, and you sre using a CRT function (memmove and similar pop up most often) that requires that code, resulting in unresolved _main. You can either fix your code, replacing CRT calls with Win32 alternatives, or remove _ATL_MIN_CRT and use the CRT startup code.


More than that, using C++ exceptions requires CRT startup code, so you can''t have both C++ exceptions and _ATL_MIN_CRT. Pick one or the other. I''ve generally found that staying away from things like the Standard C++ Library/STL in my ATL code makes it much easier to enable _ATL_MIN_CRT (most things I''d use the STL for are containers, and ATL provides non-STL-dependent containers you can use instead. If you want to minimize the user of CRT code, switch to these ATL containers rather than using STL containers).

This topic is closed to new replies.

Advertisement