Microsoft KB Archive/57362

= Variable Length String Passed from Basic to C =

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$ = &quot;This is a test&quot; + CHR$(0) CALL StringFar(SADD(a$), SSEG(a$), LEN(a$)) FOR i% = 1 TO 18 PRINT NEXT PRINT &quot;Back from C&quot; END

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

Additional query words: VBmsdos BasicCom 1.00 7.00 7.10

Keywords: KB57362

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.