开发者

/SUBSYSTEM:Windows program will not write to command line

开发者 https://www.devze.com 2022-12-25 15:07 出处:网络
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 f

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, 开发者_JAVA百科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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消