Microsoft KB Archive/105303

From BetaArchive Wiki

FIX: Redirecting Output to an MS-DOS Application PSS ID Number: Q105303 Article last modified on 07-27-1994

3.10

WINDOWS NT

The information in this article applies to:
- Microsoft Win32 Software Development Kit (SDK) for Windows NT version 3.1

SYMPTOMS

The following method is used to redirect output to a child process when it is started from a GUI application:

  1. Declare STARTUPINFO si.

    1. Set the hStdIn, hStdOut, and/or hStdErr field as desired.
    2. Set the dwFlags field to STARTF_USESTDHANDLES.
  2. In CreateProcess(), set inherit handles to TRUE.

NOTE: This method does not work when starting MS-DOS applications.

RESOLUTION

As a workaround, use AllocConsole(), then the following method:

  1. Use SetStdHandle() to set the desired handles to be inherited.

    -or-

    Use DuplicateHandle() to change the inheritance property of handles that should not be inherited.

  2. In CreateProcess(), set inherit handles to TRUE.

This method creates a blank console window; however, this is necessary because the method doesn’t work otherwise.

STATUS

Microsoft has confirmed this to be a bug in Windows NT 3.1. This problem was corrected in Windows NT 3.5.

MORE INFORMATION

Note that if you are opening a handle that will be inherited by the child, set SECURITY_ATTRIBUTES.bInheritHandle = TRUE in the call to CreateFile(), CreatePipe(), and so forth.

For an example of both methods of redirection, see the INHERIT SDK sample.

Additional reference words: 3.10 KBCategory: Prg KBSubcategory: BseProcThrd

=================================================================

Copyright Microsoft Corporation 1994.