Passing Basic 2-Dimension INTEGER Array to C by Far Reference (27303)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b

This article was previously published under Q27303

SUMMARY

The following example demonstrates how to pass a two-dimensional array of INTEGERs from compiled Basic to Microsoft C by far reference.

This information about inter-language calling applies to QuickBasic Versions 4.00, 4.00b, and 4.50 for MS-DOS and to Microsoft Basic Compiler Versions 6.00 and 6.00b 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

REM ===== Basic PROGRAM =====

 DECLARE SUB TwoIntArray CDECL (_
            BYVAL p1o AS INTEGER,_
            BYVAL p1s AS INTEGER)
CLS
DIM x(4, 4) AS INTEGER
FOR i = 0 TO 4
   FOR j = 0 TO 4
       x(i, j) = i * j
   NEXT j
NEXT i
CALL TwoIntArray(VARPTR(x(0, 0)), VARSEG(x(0, 0)))
END

/* ===== C ROUTINE ===== */ 

#include <stdio.h>
struct two_int_array{
       int a[5][5];
       };

void TwoIntArray(x)
     struct two_int_array far *x;
     /* Note: The array does not have to be in a struct. */ 
 {
    int i,j;
    for (i=0;i<5;i++)
    {
       for (j=0;j<5;j++)
       {
          printf("  %3d   ",x->a[i][j]);
       };
       printf("\n");
    };
 }

===== OUTPUT =====

    0       0       0       0       0
    0       1       2       3       4
    0       2       4       6       8
    0       3       6       9      12
    0       4       8      12      16
				

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB27303