Microsoft KB Archive/27294

From BetaArchive Wiki
Knowledge Base


Passing Basic INTEGER Array to Microsoft C by Far Reference

Article ID: 27294

Article Last Modified on 8/16/2005



APPLIES TO

  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b



This article was previously published under Q27294

SUMMARY

The example below demonstrates how to pass an array of integers from compiled Basic to Microsoft C by far reference.

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 IntArray CDECL (_
            BYVAL p1 AS INTEGER,_
            BYVAL p2 AS INTEGER)
DEFINT A-Z
DIM i AS INTEGER
DIM array(10) AS INTEGER
CLS
FOR i = 1 TO 10
   array(i) = i
NEXT i
'Array must be a FAR pointer, so offset and segment must be passed:
CALL IntArray(VARPTR(array(0)), VARSEG(array(0)))
LOCATE 15, 1
WHILE INKEY$ = "": WEND
PRINT "Back in Basic"
FOR i = 1 TO 10
   PRINT i, array(i)
NEXT i
END

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

#include <stdio.h>
void IntArray (array)
     int far *array;
 {
    int i;
    printf("Index         Value\n");
    for (i=0;i < 11; i++)
       {
         printf("  %d          %d\n",i,array[i]);
         array[i]=array[i]+100;
       };
 }
                
===== OUTPUT =====

Index      Value
  0          0
  1          1
  2          2
  3          3
  4          4
  5          5
  6          6
  7          7
  8          8
  9          9
  10         10

Back in Basic
 1             101
 2             102
 3             103
 4             104
 5             105
 6             106
 7             107
 8             108
 9             109
 10            110
                


Additional query words: QuickBas BasicCom

Keywords: KB27294