由于我经常在Microsoft Visual Studio 2017内部/外部测试我的二进制文件,因此我想控制C / C ++控制台项目中代码的行为。
我应该使用什么标志或函数来了解我的.exe是否是从Visual Studio内部启动的。
我想要实现的是:
#if !_RELEASE
system("pause"); // prevents auto shutdown of my .exe in Explorer
// double click
#endif
其中_RELEASE是在Studio启动时触发代码的某种特性,但在资源管理器双击中不可见。
我应该使用什么标志或函数来了解我的进程是否是从Visual Studio内部启动的。
它不完全是解决方案,但是:
Raymond Chen(微软winapi大师*)与我面临的问题最为接近,帮助我检测我运行控制台会话的模式或环境。
How can I tell whether my console program was launched from Explorer or from a command prompt?
printf("this process = %d\n", GetCurrentProcessId());
DWORD count = GetConsoleProcessList(nullptr, 0);
if (count == 1) {
printf("I'm the last one!\n");
Sleep(2000);
}
else {
printf("I'm not the last one! %d\n", count);
}