Microsoft KB Archive/48207

= Example of Passing Strings from C to Basic =

Article ID: 48207

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q48207



SUMMARY
The two programs below demonstrate how Microsoft C can create and pass both fixed-length and variable-length strings to Microsoft Basic.

This information about interlanguage calling applies to QuickBasic versions 4.00, 4.00b, 4.50 for MS-DOS, to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2.

For Basic PDS 7.00 and 7.10, this example works only with near strings. If you are using far strings (BC /Fs compile switch or in QBX.EXE), you must use the string-manipulation routines provided with Basic PDS 7.00 and 7.10 to change variable-length strings (StringAssign, StringRelease, StringAddress, and StringLength). For more information about using far strings, see Chapter 13 of the &quot;Microsoft Basic 7.0: Programmer's Guide&quot; for versions 7.00 and 7.10.



MORE INFORMATION
For more information about passing other types of parameters between Basic and C and a list of which Basic and C versions are compatible with each other, search in the Microsoft Knowledge Base using the following word:

BAS2C

Code Example
The following Basic program is BSUB.BAS, which invokes a C routine that creates two strings and passes them to a Basic subroutine. The Basic subroutine prints out the string (and the string's length) received from the C routine. DECLARE SUB CSUB CDECL TYPE fixstringtype       ' Must use type to pass fixed-length string B AS STRING * 26      '  in parameter list. END TYPE CALL CSUB END

SUB BASSUB(A$, B AS fixstringtype) ' Subroutine called from C      PRINT A$      PRINT LEN(A$) PRINT B.B     PRINT LEN(B.B)   END SUB The following program is CSUB.C, which builds a string descriptor that is passed to a called Basic subroutine: struct stringdesc {       int length;       /* string length */ char *string;    /* near address of the string */ }; extern void pascal bassub(struct stringdesc *basstring,                         char *basfixstring); struct stringdesc *std; char thesecondstring[26];
 * 1) include 

void csub {                                        /* create the strings */ std->length = 18; strcpy(std->string, &quot;This is the string&quot;); strcpy(thesecondstring, &quot;This is the second string&quot;); bassub(std, thesecondstring);         /* call Basic subroutine */ } To demonstrate these programs from an .EXE program, compile and link as follows: BC BSUB.BAS; CL /c /AM CSUB.C;  LINK /NOE BSUB CSUB; BSUB.EXE produces the following output:   This is the string 18  This is the second string 26

Additional query words: QuickBas BasicCom

Keywords: KB48207

-

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

© Microsoft Corporation. All rights reserved.