Variable Length String Passed from Basic to C (57362)



The information in this article applies to:

  • Microsoft Visual Basic for MS-DOS
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q57362

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]);
   }
}
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB57362