如何:检测 /clr 编译

使用 _MANAGED_M_CEE 宏查看模块是否是使用 /clr 进行编译的。 有关更多信息,请参见 /clr(公共语言运行时编译)

有关宏的更多信息,请参见 Predefined Macros

示例

// detect_CLR_compilation.cpp
// compile with: /clr
#include <stdio.h>

int main() {
   #if (_MANAGED == 1) || (_M_CEE == 1)
      printf_s("compiling with /clr\n");
   #else
      printf_s("compiling without /clr\n");
   #endif
}

请参见

参考

使用 C++ 互操作(隐式 PInvoke)