Microsoft KB Archive/57350

= Passing Integers Between QuickBASIC and MPW Pascal 3.00 =

Article ID: 57350

Article Last Modified on 5/4/2001

-

APPLIES TO


 * Microsoft QuickBasic Compiler for Macintosh 1.0

-



This article was previously published under Q57350



SUMMARY
The two programs shown below demonstrate how a Microsoft QuickBASIC program can pass integers to and from Apple MPW Pascal 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 Apple MPW (Macintosh Programmer's Workshop) Pascal, 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.

More information on interlanguage calling with Microsoft QuickBASIC can be found in the &quot;Microsoft QuickBASIC for Apple Macintosh: Language Reference,&quot; starting on page 444.

Compile and link SumIntArgs.p from Apple MPW Pascal version 3.00 as follows:

pascal -p SumIntArgs.p

link -p -rt MBPC=999 SumIntArgs.p.o BasicLib.a.o -o SumIntArgs

Note: The file BasicLib.a.o comes with Microsoft QuickBASIC for the Apple Macintosh on the Examples disk in the User Libraries:MBPC Rsrcs:MPWP PCR Folder.

Once SumIntArgs is compiled and linked, ResEdit should be used to change parameters in SumIntArgs as follows:

 In ResEdit, find the newly created file SumIntArgs and click once on the name so that it is highlighted. While holding down the COMMAND key, press the &quot;I&quot; key. This is the same as choosing Get Info from the File menu. Change the following in the dialog box that appears:

 Change the File field to &quot;SumIntArgs&quot;. Change the Type field to &quot;MBPC&quot;. Change the Creator field to &quot;MSBB&quot;.  Close the dialog box and click Yes when asked if you want to save.</li> Double-click SumIntArgs to open it. There should be one resource of MBPC displayed; double-click this also. Single-click the displayed MBPC and press COMMAND+I. In the Get Info dialog box that is brought up, change the Name field to SumIntArgs.</li></ol>

SumIntArgs is now 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 Pascal 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 PrintIntArgs(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 keypress The following Apple MPW Pascal routine is SumIntArgs.p, which accepts a series of passed integers from a Microsoft QuickBASIC program and returns the sum of the integers: {**************************************************************} { * IntSum.p (c) 1989 Microsoft Corporation                  *} {**************************************************************} { * Description: Example to show how to pass integers from   *} { *              QuickBASIC to MPW Pascal and back. *} {**************************************************************} {$R-}    { Turn off range checking} unit IntSum;

interface

{*======================== INCLUDE FILES

=
=========*}  uses {$U MemTypes.p } MemTypes, {$U BasicLibMPWP.p } {$U BasicLibMPWP.p } BasicLib;

procedure AssignInt (ptr: LIBARGPTR; val: INT16); inline $3e1f,  { move.w  (a7)+,d7  ;get int value           } $205f,  { movea.l (a7)+,a0  ;get ptr to Int variable } $3087;  { move.w   d7, (a0) ;assign the Int value    }

procedure Main;

implementation

{$S Main}

{--} { A routine to find the sum of the argument list              } {   Called from BASIC as:                                     } {   CALL IntSum (Sum, < Integer argument list >)              } {--}  procedure MAIN; var Sum, tempflag, argtype, NextInt: INT16; valptr, pSum: LIBARGPTR;

begin Sum := 0; argtype := GetNextLibArg(pSum, tempflag); argtype := GetNextLibArg(valptr, tempflag);

while (argtype <> _ARGSEND) do        begin if (argtype <> _NULLARG) then begin if (argtype = _STRGARG) then BasicError(13) else begin NextInt := IntegerArg; Sum := Sum + NextInt; end; end; argtype := GetNextLibArg(valptr, tempflag); end;

AssignInt(pSum, Sum); end; {* of MAIN *} Running SumInt produces the following output: <pre class="fixed_text">  Sum of:  2   4 and 8 Is: 14

Additional query words: MQuickB

Keywords: KB57350

-

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

© Microsoft Corporation. All rights reserved.