vbdpss.hlp (Table of Contents; Topic list)
Article Q27293
                                                 Contents  Index  Back
─────────────────────────────────────────────────────────────────────────────
                           Knowledge Base Contents  Knowledge Base Index
 
 Passing a Basic Fixed-Length String to C by Far Reference - Q27293
 
 The example below demonstrates how to pass a fixed-length string from
 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 p1o AS INTEGER,_
             BYVAL p1s AS INTEGER,_
             p3 AS INTEGER)
 
 DIM a AS STRING * 15
 
 CLS
 a = "This is a test" + CHR$(0)
 CALL StringFar(VARPTR(a), VARSEG(a), LEN(a))
 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