gpt4 book ai didi

c++ - 未处理的异常 - 如果/SUBSYSTEM 参数已更改,则访问冲突

转载 作者:行者123 更新时间:2023-11-28 02:51:21 26 4
gpt4 key购买 nike

我有一个应用程序,我在其中使用 console查看正在输出的一些值。现在一些要求已经改变,我不需要 console不再在运行时。

我试图通过切换 /SUBSYSTEM 来改变它参数,在 Project Properties->Linker->System->Subsystem 下找到来自 ConsoleWindows ,因为我对之前的事情做了同样的事情,而且它奏效了。

这次,它在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com