我正在尝试做什么
我正在使用Visual Studio来编写一个简单的基于对话框的程序。 它执行它的主要function,因为它应该。 然后,我添加了从命令提示符运行应用程序的支持。 从命令行提示符调用程序时,它仍能正常工作,但写入stdout或stderr任何消息都不会显示出来。
我试过了
我已经尝试了_tprintf() , _ftprintf(stdout,etc)多种变体_ftprintf(stdout,etc) 。 无论如何,我不能在控制台上获得任何输出。
如何决定是否显示对话框
当命令行至less包含两个参数时,程序绕过对话框直接执行程序的主逻辑,这在Go(arg1,arg2)函数中体现。 当命令行没有足够的参数时,则使用该对话框。
我的代码
这是一个非常剪裁的例子。 剩下的大部分是由Visual Studio生成的,而我刚刚添加了我自己的代码的几行。 这个例子实际上不会编译,因为有未parsing的外部引用。
Toolset v140和v140_xp,v110和v110_xp等的区别
Visual Studio 2013中的Windows XP和Windows Server 2003支持
在不考虑区域设置的情况下处理不区分大小写的情况
在VS编译程序,无需任何外部运行时DLL
C# – 将大文本文件(150MB)读入Rich Text Box
BOOL CCNCSplineApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise,any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); std::time_t* p_clock = &time_Now; CWinApp::InitInstance(); AfxEnableControlContainer(); // Create the shell manager,in case the dialog contains // any shell tree view or shell list view controls. CShellManager *pShellManager = new CShellManager; // Standard initialization SetRegistryKey(_T("MyCompany")); LPCTSTR cmdline = ::GetCommandLineW(); int argc; LPWSTR* argv = ::CommandLinetoArgvW(cmdline,&argc); if (2 < argc) { FILE*tgt = _tfopen(argv[2],_T("w")); if (0 == tgt) { _tprintf(L"Unable to open output file "%s"n",argv[2]); exit(-1); } CString inputFileName = argv[1]; Go(inputFileName,tgt); CString status = StatusText(); if (status.GetLength() > 0) { _tprintf(_T("%sn"),(LPCTSTR)status); } return FALSE; } MyDialog dlg; m_pMainWnd = &dlg; dlg.DoModal(); // Delete the shell manager created above. if (pShellManager != NULL) { delete pShellManager; } // Since the dialog has been closed,return FALSE so that we exit the // application,rather than start the application'time_doa message pump. return FALSE; }
问题
在这段代码中需要更改什么来获取各种_tprintf()调用来在控制台上显示文本?
在API中导出常量的正确方法
Windows上的OpenFST
使用sed命令来包装string
在Windows中find正确的文件大小超过4GB
Cordova Visual Studio,在Windows平板电脑上安装appx
在InitInstance()某个地方插入这段代码,之后printf() , std::cout等应该可以工作:
if( AttachConsole( ATTACH_PARENT_PROCESS ) ) { freopen( "CONIN$","rb",stdin ); // reopen stdin handle as console window input freopen( "CONOUT$","wb",stdout ); // reopen stout handle as console window output freopen( "CONOUT$",stderr ); // reopen stderr handle as console window output }
您可能还想调用_setmode(_fileno(stdout),_O_U16TEXT) (与stderr相同)以启用Unicode输出到控制台 。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。