Q57362: Variable Length String Passed from BASIC PDS 7.00 to C
Article: Q57362
Product(s): See article
Version(s): 7.00 | 7.00
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | SR# S891017-100 | mspl13_basic
Last Modified: 17-JAN-1990
The example below demonstrates how to pass a variable-length string
from a compiled BASIC program to a C program. This information applies
to Microsoft BASIC Professional Development System (PDS) 7.00 for
MS-DOS and MS OS/2.
BASIC to C Example
------------------
Compile and link as follows:
Compile: BC /Fs/d Bastest.bas;
QCL /AM Ctest.c /c
Link: LINK /noe/nod Bastest+Ctest,,,BRT70EFR+MLIBCE;
REM ===== BASIC PROGRAM =====
DECLARE SUB StringFar CDECL (BYVAL p1o AS INTEGER, BYVAL p1s AS
INTEGER, SEG p3 AS INTEGER)
CLS
a$ = "This is a test" + CHR$(0)
CALL StringFar(SADD(a$), SSEG(a$), LEN(a$))
PRINT "Back from C"
END
/* C sub-program */
#include <e:\qc2\include\stdio.h>
void StringFar(a,len)
char far *a;
int *len;
{
int i;
printf("The string is : %s \n\n",a);
printf(" Index Value Character\n");
for (i=0;i < *len; i++)
{
printf(" %2d %3d
%c\n",i,a[i],a[i]);
};
}
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.