Example of Passing a String Descriptor from MASM to Basic (49397)



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
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q49397

SUMMARY

The two programs shown below demonstrate how Microsoft assembly language can create a Basic string descriptor and pass it to Basic.

This information about interlanguage calling applies to QuickBasic versions 4.00, 4.00b, and 4.50 for MS-DOS, to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2 and to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2.

MORE INFORMATION

For more information about passing other types of parameters between Basic and MASM, search in the Microsoft Knowledge Base using the following word:

BAS2MASM

Code Example

The following Basic program is BSTRDESC.BAS, which is passed a string created in assembly language and prints the string out:
   DECLARE SUB MkString
   CALL MkString
   END
   SUB BasicSub(TheString AS STRING)
      PRINT LEN(TheString)
      PRINT TheString
   END SUB
				
The following program is ASTRDESC.ASM, which builds a string descriptor that is passed back to the calling Basic program:
.MODEL MEDIUM
        SType   STRUC
                SLength DW 18
                Soff    DW ?
        SType   ENDS
.DATA
        StringDesc  SType <>
        TheString   DB 'This is the string'

.CODE
            EXTRN BasicSub:PROC

            PUBLIC MkString
MkString    PROC
            mov ax, OFFSET TheString       ; set up string descriptor
            mov bx, OFFSET StringDesc.Soff
            mov [bx], ax
            mov ax, OFFSET StringDesc.SLength
            push ax           ; pass address of descriptor to Basic
            CALL BasicSub
            ret
MkString    ENDP
            END
				
To demonstrate these programs from an .EXE program, compile and link as follows:

BC BSTRDESC.BAS;
MASM ASTRDESC.ASM;
LINK BSTRDESC ASTRDESC;

BSTRDESC.EXE produces the following output:

This is the string


Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB49397