Variable Length String Passed from Basic to C

ID: Q57362


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2, versions 7.0, 7.1


SUMMARY

The example listed below demonstrates how to pass a variable-length string from a compiled Basic program to a C program.


MORE INFORMATION

For more information about calling C from Basic, search in the Microsoft Knowledge Base on the following word:

BAS2C

Basic to C Example

Compile and link as follows:
BC /d bastest.bas;
CL /c /AM ctest.c
LINK /noe /nod bastest.obj ctest.obj,,, VBDRT10E.lib mlibce.lib;
Use the following link line in Basic PDS for MS-DOS:
LINK /noe/nod Bastest+Ctest,,,BRT70EFR+MLIBCE;

BASTEST.BAS


DECLARE SUB StringFar CDECL (BYVAL p1o AS INTEGER, BYVAL p1s AS INTEGER,
SEG p3 AS INTEGER)
CLS
a$ = "This is a test" + CHR$(0)
CALL StringFar(SADD(a$), SSEG(a$), LEN(a$))
FOR i% = 1 TO 18
    PRINT
NEXT
PRINT "Back from C"
END 

CTEST.C


/* C subprogram */ 
#include <stdio.h>
void StringFar(char far * a, int * len)
{
   int i;
   printf("The string is: %Fs\n", a);
   printf("Index  Value  Character\n");
   for (i = 0; i < *len; i++) {
      printf(" %2d    %3d     %c\n", i, a[i], a[i]);
   }
} 

Additional query words: VBmsdos BasicCom 1.00 7.00 7.10

Keywords :
Version : MS-DOS:1.0; :7.0,7.1
Platform : MS-DOS
Issue type :


Last Reviewed: December 4, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.