Microsoft KB Archive/59533

= Passing Integers Between QuickBASIC and MPW C Version 3.00 =

Article ID: 59533

Article Last Modified on 11/21/2006



This article was previously published under Q59533



SUMMARY
The two programs below demonstrate how a Microsoft QuickBASIC program can pass integers to and from Apple MPW (Macintosh Programmer's Workshop) C version 3.00 pure code resources.

This information about interlanguage calling applies to Microsoft QuickBASIC version 1.00 for the Apple Macintosh.



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 &quot;Microsoft QuickBASIC for Apple Macintosh: Language Reference&quot; 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 &quot;User Libraries:MBPC Rsrcs:MPWC PCR&quot; 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 &quot;SumIntArgs&quot; a = 0    ' Initialize passed values b = 2 c = 4 d = 8 CALL SumIntArgs(a, b, c, d)       ' CALL Pascal routine PRINT &quot;Sum of: &quot; b;&quot; &quot;;c;&quot; and &quot;;d  ' Display returned values PRINT &quot;Is: &quot;a WHILE INKEY$ = &quot;&quot; : 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 ===================*/ 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    */ };
 * 1) include &quot;BasicMPWC.h&quot;

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

Additional query words: MQuickB

Keywords: KB59533

-

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

© Microsoft Corporation. All rights reserved.