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

标签 c++ visual-studio-2012 mfc linker

我有一个应用程序,我在其中使用 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/

相关文章:

python - 使用现有 C 对象初始化 Cython 对象

c++ - 尝试在 Blackberry Cascades QT 和 QML 中下载图像

c++ - 从容器类中查找小于或大于范围的值

visual-studio - Visual Studio 11 电动工具 checkin 策略

c# - 无法使用 SSDT Visual Studio 2012 "Unable to determine the database platform type. The database may be unavailable.."比较数据库架构

c++ - 消息映射宏

c++ - 在嵌套 Lambda 中捕获 Lambda 的静态

asp.net - 无法在 Visual Studio 中添加 .ashx 文件

c++ - 增强元文件说明

visual-studio-2010 - MFC-两个CDialog之间的通信