检测托管C ++中的调试模式

时间:2009-03-04 18:49:34

标签: .net c++ .net-2.0

在Managed C ++ / C ++ / CLI中检测应用程序是否以调试模式运行的最佳方法是什么?

2 个答案:

答案 0 :(得分:5)

IsDebuggerPresent()

或者它是否使用调试构建?对于常规C ++,它很容易(定义了_DEBUG),对于托管我不知道。

答案 1 :(得分:1)

array<Object^>^ debuggableAttributes = Assembly::GetExecutingAssembly()->GetCustomAttributes(DebuggableAttribute::typeid, false);

Console::WriteLine(debuggableAttributes->Length > 0);

(在调试模式下编译时,编译器将DebuggableAttribute添加到程序集中)