Microsoft KB Archive/48208

= Example Passing char from C to Basic =

Article ID: 48208

Article Last Modified on 11/21/2006



This article was previously published under Q48208



SUMMARY
The two programs shown below demonstrate how a Microsoft C routine can pass a char to Basic.

This information about interlanguage calling applies to QuickBasic Versions 4.00, 4.00b, and 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) Version 7.00 for MS-DOS and MS OS/2.



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, query 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 passes a char to a Basic subroutine, which then prints out the received character (and its length): DECLARE SUB CSUB CDECL TYPE char                 ' must declare user-defined TYPE to hold character AS STRING *1 '  char, as there are no single-byte END TYPE                  '  TYPEs in Basic CALL CSUB END

SUB BASSUB(cchar AS char) ' subroutine called by C routine PRINT cchar.character PRINT LEN(cchar.character) END SUB The following program is CSUB.C, which passes a char to a Basic subroutine: struct character        /* must declare as struct so type casting */ {                /* won't affect value */ char thechar; }; extern void pascal bassub(struct character *baschar); struct character *c_char;
 * 1) include 

void csub {  c_char->thechar = 'A'; bassub(c_char);

} 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:   A   1

Additional query words: QuickBas BasicCom

Keywords: KB48208

-

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

© Microsoft Corporation. All rights reserved.