Article ID: 48205
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 Professional Development System 7.0
- Microsoft BASIC Professional Development System 7.1
- Microsoft BASIC Compiler 6.0
- Microsoft BASIC Compiler 6.0b
This article was previously published under Q48205
SUMMARY
The two programs below demonstrate how a Microsoft Basic function can return a string to C.
For Basic PDS 7.00 and 7.10, this example applies to near strings only. If you are using far strings (/Fs during compile or in the QBX.EXE environment), you must use the string-manipulation routines supplied with Basic PDS 7.00 and 7.10 (StringAssign, StringRelease, StringAddress, and StringLength). For more information about using far strings, see Chapter 13 of the "Microsoft Basic 7.0: Programmer's Guide" 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 BSTRF.BAS, which contains a function that returns a string to a calling C routine:
DECLARE SUB CSUB CDECL () CALL CSUB END FUNCTION basvarfunc$(dummy%) basvarfunc$ = "This is the string" END FUNCTION
The following program is CSTRF.C, which calls a Basic routine that returns a string. A string descriptor is created to receive the data returned by the Basic function.
#include <stdio.h> struct stringdesc { int length; /* string length */ char *string; /* string address */ }; extern struct stringdesc * pascal basvarfunc(int *dummy); struct stringdesc *std; void csub() { int i; std = basvarfunc(0); printf("Length of string: %2d\r\n", std->length); for(i = 0; i < std->length; i++) printf("%c", std->string[i]); printf("\r\n"); }
To demonstrate these programs from an .EXE program, compile and link as follows:
BC BSTRF.BAS;
CL /c /AM CSTRF.C;
LINK /NOE BSTRF CSTRF;
BSTRF.EXE produces the following output:
Additional query words: QuickBas BasicCom
Keywords: KB48205