Microsoft KB Archive/49397

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 10:20, 21 July 2020 by X010 (talk | contribs) (Text replacement - ">" to ">")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


Example of Passing a String Descriptor from MASM to Basic

Article ID: 49397

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Professional Development System 7.0
  • Microsoft BASIC Professional Development System 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



Additional query words: QuickBas BasicCom

Keywords: KB49397