/SUBSYSTEM:Windows 程序不会写入命令行

发布于 2024-08-27 08:52:24 字数 249 浏览 5 评论 0原文

我在 Visual Studio 2005 中有一个混合模式 C++-CLI 程序,该程序设置为使用 /SUBSYSTEM:Windows。一般来说,它是一个图形应用程序,从其快捷方式或通过注册到它的文件类型启动。

但是,在极少数情况下,用户希望使用参数从命令行运行它。我可以很好地访问参数,当涉及到写入控制台时,响应从带有参数的命令行启动的程序,我没有看到 Console::WriteLine 有任何效果。

我做错了什么?

I have a mixed mode C++-CLI program in Visual Studio 2005 that is set to use the /SUBSYSTEM:Windows. Generally speaking it is a graphical application that is launched from its shortcut or through the filetype registered to it.

However, there is a rare occasion where a user will want to run it from the command line with arguments. I can access the arguments just fine, its when it comes to writing to the console, in response to the program being launched from the command line with arguments, where I don't see Console::WriteLine having any effect.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨落画卷 2024-09-03 08:52:24

这很烦人,我同意。你没有做错什么,这是 Windows 设置方式的一个怪癖。

至少在某些情况下可以解决此问题,请参阅 http://blogs.msdn.com/junfeng/archive/2004/02/06/68531.aspx。不过,我还没有遇到任何其他人真正使用过这些方法。

大多数人的 IME 只是创建两个版本的具有不同名称的可执行文件,一种用于批处理用户(“myapp.exe”),另一种用于从开始菜单运行时(“myappw.exe”)。

有关详细信息,请参阅 如何输出到控制台中的一些建议C++/Windows 可能有用。

This one's annoying, I agree. You're not doing anything wrong, it's a quirk of the way Windows is set up.

It is possible to solve this, at least in some cases, see http://blogs.msdn.com/junfeng/archive/2004/02/06/68531.aspx . I've not come across anybody else who's actually used these methods though.

Most people IME just create two versions of the executable with different names, one for batch users ("myapp.exe") and one for when it's run from the start menu ("myappw.exe").

For more information, some of the suggestions at How to output to the console in C++/Windows may be useful.

荒岛晴空 2024-09-03 08:52:24

这是一个老问题 - 请参阅 http://www.codeproject.com/KB/cpp/ EditBin.aspx 的解决方案

您还可以重新打开控制台编辑流

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE /*hPrevInst*/, LPSTR cmd_line, int showmode)
{
  AllocConsole(); //create a console
  ifstream conin("con");   // not sure if this should be "con:" ?
  ofstream conout("con");
  cout.rdbuf(conout.rdbuf()); 
  cerr.rdbuf(conout.rdbuf());      
  cin.rdbuf(conin.rdbuf());


  FreeConsole();
  return 0;
}

:抱歉,这是纯 C++,不了解 C++/cli

It's an old problem - see http://www.codeproject.com/KB/cpp/EditBin.aspx for solutions

You can also reopen the streams to a console

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE /*hPrevInst*/, LPSTR cmd_line, int showmode)
{
  AllocConsole(); //create a console
  ifstream conin("con");   // not sure if this should be "con:" ?
  ofstream conout("con");
  cout.rdbuf(conout.rdbuf()); 
  cerr.rdbuf(conout.rdbuf());      
  cin.rdbuf(conin.rdbuf());


  FreeConsole();
  return 0;
}

edit: sorry this is pure C++, don't know about C++/cli

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文