我有一个应用程序,我在其中使用 console
查看正在输出的一些值。现在一些要求已经改变,我不需要 console
不再在运行时。
我试图通过切换 /SUBSYSTEM
来改变它参数,在 Project Properties->Linker->System->Subsystem
下找到来自 Console
至 Windows
,因为我对之前的事情做了同样的事情,而且它奏效了。
这次,它在 mfc110u.dll
中给我一个未处理的异常,因为无法实例化对象。
为什么会出现此异常,我还能如何关闭 console
与正在运行的程序?我正在使用 VS2012
作为开发环境。
最佳答案
如果您不需要控制台,请声明一个 winmain。这是非unicode版本
#include <windows.h>
#include <iostream>
#include <cstdio>
int main (int, char**);
// If we just start with main, we will always get a console window
int WINAPI WinMain (
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
int argc = __argc;
char** argv = __argv;
#ifdef DEBUG
// If we are running in debug mode, open a console window
AllocConsole();
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);
#endif
return main (argc, argv);
}
int main (
int argc,
char** argv
)
{
MessageBox(NULL, "Whoo hoo", "It Works!!!", MB_OK);
return 0;
}
关于c++ - 未处理的异常 - 如果/SUBSYSTEM 参数已更改,则访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22980875/