StringAddress Routine ---------------------------------------------------------------------------- Action Used in mixed-language programming to returns the far address of a variable-length string. Syntax far-address = StringAddress( string-descriptor%); Remarks The syntax above is for the C language. For MASM, Pascal, and FORTRAN examples, see Chapter 13, "Mixed-Language Programming with Far Strings" in the Programmer's Guide. StringAddress returns the far address of the variable-length string defined by string-descriptor%. The argument string-descriptor% is the near address of a string descriptor within a non-BASIC routine. A non-BASIC routine uses StringAddress to find the far address of a BASIC variable-length string. Calls to the StringAddress routine always are made from a non-BASIC routine to find the address of a string that was transferred to BASIC from the non-BASIC routine. For example, assume that you have passed a string from a MASM routine to BASIC's string space using StringAssign. The descriptor for the string exists at offset descriptor. MASM can find the far address of the string data using the following code. leaax, descriptor ; offset of descriptor pushax extrnstringaddress. proc far callstringaddress The far address is returned in DX.AX. DX holds the segment and AX holds the offset. Note If you are not doing mixed-language programming, there usually is no reason to use StringAddress. Instead, use SSEGADD to find the far address of a variable-length string. For more information on mixed-language programming with strings, see Chapter 12, "Mixed-Language Programming" and Chapter 13, "Mixed-Language Programming with Far Strings" in the Programmer's Guide. See Also SSEGADD, StringAssign, StringLength, StringRelease Example The following example shows how to use StringAddress and StringLength, routines in the BASIC main library. The program creates a string in BASIC, then passes it to MASM, which uses StringAddress to find the data that needs to be printed. It uses StringLength to tell the system the length of the string. DEFINT A-Z ' Create a variable-length string. Message1$ = "This string was sent to MASM for printing." ' Pass it to MASM to be printed. CALL PrintMessage1(Message1$) The following MASM procedure must be assembled and the .OBJ file linked to the BASIC code listed above. ; *************************PrintMessage1************************ ; Prints a string passed by BASIC. .model medium, basic; Use same model as BASIC. .code ; Define procedure with one-word argument. PrintMessage1 procuses ds, descriptor ; Define external (BASIC library) procedures. extrnStringAddress. proc far extrnStringLength. proc far mov ax, descriptor ; Find length of string. pushax callStringLength pushax; Save length on stack. mov ax, descriptor ; Go find out the pushax; address of the string CALLStringAddress; data. mov ds, dx ; Address of string. mov dx, ax mov bx, 01 ; Handle of printer. pop cx; Length of string. mov ah, 40h ; Have DOS print it. int 21h ret PrintMessage1 endp end