Article ID: 57362
Article Last Modified on 8/16/2005
APPLIES TO
- Microsoft Visual Basic for MS-DOS
- Microsoft BASIC Professional Development System 7.0
- Microsoft BASIC Professional Development System 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]); } }
Additional query words: VBmsdos BasicCom 1.00 7.00 7.10
Keywords: KB57362