CALLing C I/O Routines Does Not Affect QB Cursor Position (27486)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0

This article was previously published under Q27486

SUMMARY

Problem:

Microsoft C routines (medium model) linked with a compiled Basic program that do screen output [such as printf ("hello, world.\n");] do not update the cursor position after returning to the calling Basic program.

For example, after 1) doing a PRINT from Basic, 2) CALLing a C routine that does some printf's, and 3) returning to Basic, the next PRINT statement goes directly after the last Basic PRINT statement, ignoring the \n's (newline characters) from the called C routine.

Response:

This is expected behavior. C routines should not change the Basic cursor position. This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b, and to Microsoft Basic Professional Development System (PDS) Version 7.00.

To work around this limitation, OPEN "CONS:" as a device in Basic and print to the console (screen) using PRINT# or PRINT# USING in Basic. This forces Basic to go through the operating system's console device instead of using direct writes to video memory.

The following is a code example where a C function doesn't change the cursor position in Basic:
 'The following QuickBasic program prints:
   ' Hello.
   ' Goodbye.t part of this line gets erased.
   DECLARE SUB CRoutine CDECL ()
   CLS
   PRINT "Hello."
   CALL CRoutine
   PRINT "Goodbye."


   /* C program */ 
   #include <stdio.h>
   void croutine ()
   {
   printf ("The first part of this line gets erased.\n");
   }
				

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB27486