Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Article Q27327
◄Contents► ◄Index► ◄Back►
─────────────────────────────────────────────────────────────────────────────
◄Knowledge Base Contents► ◄Knowledge Base Index►
Passing COMMON Variables from Basic to C by Far Reference - Q27327
The following example demonstrates how to pass COMMON variables from
compiled Basic to Microsoft C by far reference.
This information applies to the Standard and Professional Editions of
Microsoft Visual Basic version 1.0 for MS-DOS and to Microsoft C
Compiler version 7.0.
To compile this example in Visual Basic for MS-DOS, execute the
following commands:
BC BMODULE.BAS;
CL -c -AM CMODULE.C
LINK BMODULE.OBJ CMODULE.OBJ;
Basic Program
-------------
DECLARE SUB RCommon CDECL (_
BYVAL p1o AS INTEGER,_
BYVAL p1s AS INTEGER)
COMMON SHARED element1 AS INTEGER, element2 AS STRING * 20,_
element3 AS SINGLE
element1 = 23
element2 = "DATE : " + DATE$ + CHR$(0)
element3 = 309.03
CALL RCommon(VARPTR(element1), VARSEG(element1))
END
C Routine
---------
#include <stdio.h>
struct common_block { // Structure that looks like the Basic
int a; // common block.
char b[20];
float c;
};
void RCommon(struct common_block far *pointer) {
printf("Element1 = %d\", pointer->a);
printf("Element2 = %Fs\", pointer->b);
printf("Element3 = %f\", pointer->c);
}
Output
------
Element1 = 23
Element2 = DATE : 02-02-1988
Element3 = 309.029999