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 Q27326
◄Contents► ◄Index► ◄Back►
─────────────────────────────────────────────────────────────────────────────
◄Knowledge Base Contents► ◄Knowledge Base Index►
Passing Basic Variable-Length String to C by Far Reference - Q27326
The following example demonstrates how to pass a variable-length
string variable 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 StringFar CDECL (BYVAL addr AS LONG, ln AS INTEGER)
CLS
a$ = "This is a test" + CHR$(0)
CALL StringFar(SSEGADD(a$), LEN(a$))
LOCATE 20, 1
END
C Routine
---------
#include <stdio.h>
void StringFar(char far *a, int *len) {
int i;
printf("The string is : %Fs\\",a);
printf(" Index Value Character\");
for (i=0;i < *len; i++) {
printf(" %2d %3d %c\", i, a[i], a[i]);
}
}
Output
------
The string is : This is a test
Index Value Character
0 84 T
1 104 h
2 105 i
3 115 s
4 32
5 105 i
6 115 s
7 32
8 97 a
9 32
10 116 t
11 101 e
12 115 s
13 116 t
14 0