|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionIf you create a Windows program using the MFC Application Wizard, the program will not show text output which has been sent to the Standard Output or Standard Error handles. Visibility of the output may be desirable at some point in time for diagnostic or functional purposes. Or you may wish to add command line operation of the program. Then to be consistent with command line operation, text should automatically be output to the command/dos window. This article documents the use of EditBin utility to activate console mode operation of a Windows (or GUI ) program. (And for those who want some source code, the program contains an EditBin program relating to redirection of the Alternatives for obtaining text outputRun the Windows program from a command prompt and redirect the output using the redirection feature of the command window: ">out.txt" and "2>errors.txt" Reassign the standard output and error output handles to be piped or sent to another file using You may write a console program that remaps the The Microsoft EditBin UtilityEditBin.exe is found in the VC98\bin subpath of Visual Studio 6. This obscure tool offers the key for enabling text console output from Windows mode programs written in Visual C++ 6 (or Visual Basic 6). You can toggle the program executable between Windows mode and console mode.
Including the Editbin utility in the build processThe article image shows Visual Studio 6 Project Settings to show in situ how the Microsoft EditBin utility appears when added to become part of the build process. The "Post-Build Step" tab of the Projects Settings dialog allows you to enter in a command on your final executable. The picture shows the example: editbin /SUBSYTEM:CONSOLE $(OUTDIR)\iTHXTool.exe
Side Effect for a Console version of the programThe console window will be appear along with the application window. Such may be the desired option if you want to view diagnostic information. If you start the program from a command prompt, the command window will show the Standard Output and Standard Error text. You may have to create two copies of your application: a strictly GUI program, and a command line version. The programs will involve the same compiled code, but one will be modified using the EditBin tool. Also a Microsoft help entry mentioned that the file handles 0,1 and 2 (that should be equivalent somehow to One last observation on the VS6 project settings...You may notice "/subsystem:windows" as appears in an MFC Wizard generated application under the Project Settings Link tab. Yet console output can't be obtained by simply changing this entry to /subsystem:console. Some code for redirection of coutThe source code program here, provides an example for redirecting the The application consists of a text editor window that is automatically filled with the time of day at ten seconds intervals. The program relies on piped output which is being read by a The heart of the redirection occurs within the initialization of the main application object. For all related code, search for the "April 2005" string which will lead you to all code modifications to the standard wizard generated code. Initialization Stepsrval = CreatePipe(&hRead,&hWrite,0,0); rval = SetStdHandle(STD_OUTPUT_HANDLE,hWrite); //Now assign hWrite to stdout, cout FILE *fp; int hConHandle; long lStdHandle; lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "w" ); // The stdout reassignment didn't seem to work // *stdout = *fp; // redefine the stdout to point to the pipe setvbuf( fp, NULL, _IONBF, 0 ); // Filebuf object attached to "test.dat" filebuf *fb = new filebuf(_fileno(fp ) ); cout = fb; This program shows a little bit of how redirection can be done. Note that the buffering of text (for text being inserted into the RTF document) is not designed ruggedly. The code bypasses the need to use the Microsoft EditBin.exe tool in some but not all cases. It would have been desirable to write the data to a memory file instead of sending data through a pipe. Then there would not have been a need to create a thread to watch the output of the pipe. Anyhow, the ConclusionThe Windows GUI development doesn't conveniently support the access to
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||