MORE INFORMATION
When doing interlanguage calling with Microsoft QuickBASIC, the other
language can make calls to the BASIC run time to get the address of
passed arguments. This is accomplished with the GetNextLibArg
statement.
GetNextLibArg returns a pointer to a variant record containing another
pointer to each possible type of QuickBASIC variable (single
precision, double precision, integer, etc.). Usually a double
indirection of pointers is used to get the actual passed data.
Using double indirection of pointers with LSC or Apple MPW C, however,
does not return the correct value. This is a QuickBASIC header file
problem. The routine below demonstrates how an inline
assembly-language routine can be used in place of the double
indirection to work around the problem.
For more information on interlanguage calling with Microsoft
QuickBASIC, see the "Microsoft QuickBASIC for Apple Macintosh:
Language Reference" manual, starting on page 444.
Compile and link SumIntArgs.c from Apple MPW Pascal version 3.00 as
follows:
c -p SumIntArgs.c
link -p -c MSBB -o SumIntArgs -rt MBPC=2 -t MBPC -sn MAIN=SumIntArgs
BasicLib.a.o SumIntArgs.c.o
Note: The file BasicLib.a.o comes with Microsoft QuickBASIC for the
Apple Macintosh on the Examples disk in the "User Libraries:MBPC
Rsrcs:MPWC PCR" folder.
After compiling and linking, SumIntArgs is a pure code resource that
can be used with the SumInt QuickBASIC program.
Code Example
The following QuickBASIC program is SumInt, which invokes an Apple MPW
C routine to sum a series of passed integers:
DEFINT a-z
LIBRARY "SumIntArgs"
a = 0 ' Initialize passed values
b = 2
c = 4
d = 8
CALL SumIntArgs(a, b, c, d) ' CALL Pascal routine
PRINT "Sum of: " b;" ";c;" and ";d ' Display returned values
PRINT "Is: "a
WHILE INKEY$ = "" : WEND ' Wait for key press
The following Apple MPW C routine is SumIntArgs.c, which accepts a
series of passed integers from a Microsoft QuickBASIC program and
returns the sum of the integers:
/*************************************************************
* IntSum.c (c) 1989 Microsoft Corporation *
*************************************************************
* Description: Example to show how to pass integers from *
* QuickBASIC to MPW C and back. *
*************************************************************/
/*========================= INCLUDE FILES ===================*/
#include "BasicMPWC.h"
pascal void AssignInt(LIBARGPTR ptr, INT16 val) = {
0x3E1F, /* move.w (a7)+,d7 ; get int value */
0x205F, /* movea.l (a7)+,a0 ; get ptr to Int variable */
0x3087 /* move.w d7, (a0) ; assign the Int value */
};
PUBLIC VOID MAIN() {
INT16 tempflag, argtype, NextInt, Sum;
LIBARGPTR valptr, pSum;
Sum = 0;
argtype = GetNextLibArg(&pSum, &tempflag);
argtype = GetNextLibArg(&valptr, &tempflag);
while (argtype != _ARGSEND) {
if (argtype != _NULLARG)
if (argtype == _INTARG) {
NextInt = IntegerArg();
Sum = Sum + NextInt;
}
argtype = GetNextLibArg(&valptr, &tempflag);
}
AssignInt(pSum, Sum);
} /* MAIN */
Running SumInt produces the following output:
Sum of: 2 4 and 8
Is: 14