PRB: freopen() Function Fails in QuickWin Libraries

Last reviewed: July 17, 1997
Article ID: Q76664
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg kbprb

The information in this article applies to:

  • The C Run-time (CRT), included with:

        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

The freopen() function in the Microsoft C run-time library fails if an application attempts to reassign stdin, stdout, or stderr in a QuickWin window. The sample code below demonstrates this behavior.

CAUSE

This limitation is caused by a design restriction in the QuickWin implementation. QuickWin does not supporting stdin, stdout, or stderr (unlike MS-DOS and OS/2). Because QuickWin assigns all three standard streams to the same file handle, closing one stream affects the others. In MS-DOS and OS/2, each stream has its own file handle that the application can manipulate without affecting the other streams.

RESOLUTION

Do not reassign stdin, stdout, or stderr while in a QuickWin window.

MORE INFORMATION

Sample Code

/* Compile options needed: QuickWin EXE
*/

#include <stdio.h>
#include <process.h>

FILE *stream, *errstream;

void main(void)
{
   /* Reassign "stdout" to "data2" */
   stream = freopen("data2", "w", stdout);

   if (stream == NULL )              /* If reassignment failed */
      printf("error on freopen\n");
   else
   {
      fprintf(stream,"This will go to the file `data2'\n");
      printf("`stdout' successfully reassigned\n");
      fclose(stream);
   }
   exit(0);
}


Additional reference words: 1.00 1.50 7.00
KBCategory: kbprg kbprb
KBSubcategory: CRTIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.