简体   繁体   English

如何判断我正在运行的Microsoft C ++代码是使用/ EHa开关编译的?

[英]How can I tell if the Microsoft C++ code I'm running was compiled with the /EHa switch?

I need to make sure the header I'm using is compiled with the /EHa compiler switch? 我需要确保正在使用的标头是使用/ EHa编译器开关编译的吗?

How can I do that? 我怎样才能做到这一点?

inline bool CodeHasEHaSwitch()
{
    bool dtorCalled = false;

    struct CCheckEHaSwitch
    {
        CCheckEHaSwitch( bool& dtorCalled) : dtorCalled( dtorCalled ) {}
        ~CCheckEHaSwitch() {  dtorCalled = true; }
        bool& dtorCalled;

        static void Win32ExceptionTranslator( unsigned int nExceptionCode,
        EXCEPTION_POINTERS *pExceptionInfo )
        {  throw nExceptionCode; }
    };

    _se_translator_function pfnPrevSeTranslator =
        _set_se_translator( CCheckEHaSwitch::Win32ExceptionTranslator );
    try
    {
        CCheckEHaSwitch test( dtorCalled );

        *((int*)0) = 0;  // generate access violation
    }
    catch (unsigned int)
    {
    }

    _set_se_translator( pfnPrevSeTranslator );

    return dtorCalled;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将/ EHa添加到使用Microsoft Visual C ++编译器的QtCreator - Add /EHa to QtCreator that used Microsoft Visual C++ Compiler 如何分析在 Windows 上运行的 C++ 代码? - How can I profile C++ code running on Windows? 如何防止使用C ++或本机编译代码进行I / O访问 - How to Prevent I/O Access in C++ or Native Compiled Code 如何从 C++ 代码编译的 Web 程序集开始下载? - How can I start a download from c++ code compiled web assembly? 在C ++中,我如何告诉WHICH代码正在分配什么类型的对象? - In C++, how can I tell WHICH piece of code is allocating what TYPE of objects? 如何在AutoIt中访问类似于数组的字符串? (我正在将代码从C ++移植到AutoIt) - How can I access a string like an array in AutoIt? (I'm porting code from C++ to AutoIt) 如何判断用户是否尝试在C ++中关闭窗口? - How can I tell if the user tries to close the window in C++? 在C ++中,如何分辨整数和字符之间的区别? - In C++ How can I tell the difference between integers and characters? 如何使用编译的C代码编译和链接C ++代码? - How do I compile and link C++ code with compiled C code? C ++如何将字符串转换为枚举以在开关中使用它? - C++ How can I convert a string to enum to use it in a switch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM