Passing Long Integers Between Macintosh QuickBASIC and MPW C (59486)






This article was previously published under Q59486

SUMMARY

The two programs below demonstrate how a Microsoft QuickBASIC program can pass long integer variables 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.

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

Compile and link PrintLng.c from Apple MPW C version 3.00 as follows:
   c -p PrintLng.c

   link -p -c MSBB -o PrintLng -rt MBPC=2 -t MBPC -sn Main=PrintLng
   BasicLib.a.o PrintLng.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.

Once compiled and linked, PrintLng is a pure code resource that can be used with the RetLng QuickBASIC program.

Code Example

The following QuickBASIC program is RetLng, which invokes an Apple MPW C routine to return a series of long integer numbers:
   LIBRARY "PrintLng"
   A& = 0 : B& = 0
   CALL PrintLng(A&, B&)
   PRINT A&; B&
   WHILE INKEY$ = "" : WEND
				
The following Apple MPW C routine is PrintLng.c, which accepts a series of passed long-integer numbers from a Microsoft QuickBASIC program and returns a constant value in them:
/**************************************************************
 * PrintLng.c (c) 1990 Microsoft Corporation                  *
 **************************************************************
 * Description: Example to show how to pass long integer      *
 *              numbers from QuickBASIC to MPW C and back.    *
 **************************************************************/ 

#include "BasicMPWC.h"

pascal void AssignLng(LIBARGPTR ptr, LONGINT val) = {
   0x225F,  /* movea.l (a7)+,a1                             */ 
   0x2E19,  /* move.l  (a1)+,d7   ;get Long value           */ 
   0x205F,  /* movea.l (a7)+,a0   ;get ptr to variable      */ 
   0x20C7   /* move.l   d7, (a0)+ ;assign the value         */ 
};

/*------------------------------------------------------------*
 * A routine to pass back to BASIC single precision constants *
 *    Called from BASIC as:                                   *
 *    CALL PrintLng (< long integer argument list >)          *
 *------------------------------------------------------------*/ 

PUBLIC VOID MAIN() {
   INT16         tempflag, argtype;
   LIBARGPTR     valptr;
   LONGINT       templng;

   argtype = GetNextLibArg(&valptr, &tempflag);

   while (argtype != _ARGSEND) {
      if (argtype != _NULLARG)
         if (argtype == _LONGARG) {
            templng = 4321;
            AssignLng(valptr, tempdbl);
         }
      argtype = GetNextLibArg(&valptr, &tempflag);
   }

} /* MAIN */ 
				
Running RetLng produces the following output:
   4321  4321
				

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: KB59486