Microsoft KB Archive/79374

= Passing Basic PDS Variable-Length String By Far Reference to C =

Article ID: 79374

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q79374



SUMMARY
The example of passing a Basic variable-length string to C by far reference on page 25 of the Microsoft application note titled, &quot;How to Pass Parameters Between Basic and C,&quot; BQ0080, needs to be modified in two places to work with Basic PDS versions 7.0 and 7.1. The corrected example is shown below.



MORE INFORMATION
This application note (BQ0080) can be obtained by calling Microsoft Technical Support or by searching in the Microsoft Knowledge Base.

Please see the following articles in the Microsoft Knowledge Base:

50062 How to Pass Parameters Between Basic and C (Part 1 of 2)

71274 How to Pass Parameters Between Basic and C (Part 2 of 2)

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

The following are two changes to the example of &quot;Passing Basic Variable-Length String to C by Far Reference&quot; in the application note BQ0080:

  The first change is in the Basic code. The call to StringFar, which reads as follows: Call StringFar ( SADD(a$), VARSEG (a$), LEN(a$)) Should read as follows: Call StringFar ( SADD(a$), SSEG (a$), LEN(a$)) In Basic PDS, VARSEG is used to find the segment of fixed-length variables. SSEG must be used to get the segment address of far variable-length strings because the segment is obtained from the descriptor for these variables, not from the location of the data itself, as is the case with VARSEG.  The second change you must make is in the C code. If you run the example, even with the above change, you will see that the first C printf fails, while the other two work. The problem is that the address being passed to the printf in the first printf is a near pointer, when the pointer needs to be a far address. To force the printf to interpret &quot;a&quot; as a far address, simply replace the %s with %Fs. If you compile the C code for large memory model, however, this problem does not occur, because all references are then far by default.

Corrected Code Example
REM ===== Basic PROGRAM =====

DECLARE SUB StringFar CDECL (_       BYVAL p1o AS INTEGER,_        BYVAL p1s AS INTEGER,_        SEG p3 AS INTEGER) CLS a$ = &quot;This is a test&quot; + CHR$(0) ' For the second parameter in the call to StringFar: ' Use SSEG(a$) for Basic PDS 7.0/7.1. ' Use VARSEG(a$) for QuickBasic 4.0/4.0b/4.5 or Basic Compiler 6.0/6.0b. CALL StringFar(SADD(a$), SSEG(a$), LEN(a$)) END

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

void StringFar(a,len) char far *a; int *len; {   int i;    /*  If linking this C code with Basic PDS, use %Fs as shown: */ printf(&quot;The string is : %Fs \n\n&quot;,a); printf(&quot; Index      Value       Character\n&quot;); for (i=0;i < *len; i++) {        printf(&quot;  %2d          %3d            %c\n&quot;,i,a[i],a[i]); }; } ===== OUTPUT =====
 * 1) include 

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

Additional query words: BasicCom 7.00 7.10

Keywords: kbcode KB79374

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.