Passing Basic Array of Variable-Length Strings to C (27299)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • 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 Q27299

SUMMARY

The following example demonstrates how to pass an array of variable-length strings from compiled Basic to Microsoft C.

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 StringArray CDECL (_
            BYVAL p1o AS INTEGER,_
            BYVAL p2s AS INTEGER)
CLS
DIM array$(10)
FOR i = 0 TO 10
  array$(i) = STRING$(9, 65 + i) + CHR$(0)
NEXT i
CALL StringArray(VARPTR(array$(0)), VARSEG(array$(0)))
END

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

#include <stdio.h>
struct struct_string{      /* structure that looks like a */ 
     int length;           /* string descriptor           */ 
     char *address;
     };
void StringArray(string)
   struct struct_string far *string;
 {
    int i;
    printf(" Index  Length    String\n");
    for (i=0;i < 10; i++)
       {
         printf("  %2d     %3d     %s\n",i,string->length,
                string->address);
         string++;
       };
 }
				
===== OUTPUT =====
 Index  Length    String

   0      10     AAAAAAAAA
   1      10     BBBBBBBBB
   2      10     CCCCCCCCC
   3      10     DDDDDDDDD
   4      10     EEEEEEEEE
   5      10     FFFFFFFFF
   6      10     GGGGGGGGG
   7      10     HHHHHHHHH
   8      10     IIIIIIIII
   9      10     JJJJJJJJJ
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB27299