Microsoft KB Archive/85265

= How to Create a Near String when Using Far Strings =

Article ID: 85265

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q85265



SUMMARY
This article describes how a Basic program compiled for far strings can create and pass a near string descriptor to a procedure written in C or a language other than Basic.



MORE INFORMATION
The following example Basic program creates a near string descriptor and calls a sample C function that expects to receive a near string descriptor:

Example Program
TYPE descriptortype    ' This TYPE statement defines a near string ' descriptor. length AS INTEGER offset AS INTEGER END TYPE

DECLARE SUB stringnear CDECL (descript AS descriptortype)

DIM descriptor AS descriptortype CLS DIM tempstring AS STRING * 255 ' This string must be one character ' longer than the maximum length you ' expect your string to be. a$ = &quot;It Works!!&quot; + CHR$(0)    ' Some library routines expect a NUL ' appended to the end of the string. descriptor.length = LEN(a$) tempstring = a$ descriptor.offset = VARPTR(tempstring)' Get the address of the string. PRINT &quot;In basic length of the string is &quot;; LEN(a$) CALL stringnear(descriptor)' Call the C subprogram. PRINT: PRINT: PRINT END The following C function receives a near string descriptor as a parameter: struct descriptor_struct /* Defines the near string descriptor. */ { int length; char *offset; };
 * 1) include 

void stringnear(struct descriptor_struct *descriptor){ printf(&quot;In C length of the string is: %d \n\n&quot;, descriptor->length); printf(&quot;The string text is : %s \n\n&quot;, descriptor->offset); } Compile the Basic program above with:   BC /FS Basic.BAS; Compile the C program above with:   CL -c -AM  C.C (NOTE: The C compiler used to compile this program must be compatible with Basic PDS.)

Link the modules together with: LINK /NOE Basic.OBJ+C.OBJ,,, BRT71EFR.LIB+MLIBCE.LIB; For more information about calling C from Basic, query on the following word in the Microsoft Knowledge Base:

BAS2C

Additional query words: BasicCom 7.10 bas2c

Keywords: KB85265

-

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

© Microsoft Corporation. All rights reserved.