home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / basic / mxadstb.bas < prev    next >
Encoding:
BASIC Source File  |  1989-11-09  |  1.3 KB  |  35 lines

  1. DEFINT A-Z
  2.  
  3. 'Start program in BASIC for proper initialization.
  4. ' Define external and internal procedures.
  5. DECLARE SUB shakespeare ()
  6. DECLARE SUB StringAssign (BYVAL srcsegment, BYVAL srcoffset, BYVAL srclen, BYVAL destsegment, BYVAL destoffset, BYVAL destlen)
  7. DECLARE SUB addstring (instrg1off, instrg1len, instrg2off, instrg2len, outstrgoff, outstrglen)
  8. DECLARE SUB StringRelease (s$)
  9.  
  10. 'Go to main routine in second language
  11. CALL shakespeare
  12.  
  13. 'The non-BASIC program calls this SUB to add the two strings together
  14. SUB addstring (instrg1off, instrg1len, instrg2off, instrg2len, outstrgoff, outstrglen)
  15.  
  16. 'Create variable-length strings and transfer non-BASIC fixed strings to them.
  17. 'Use VARSEG() to compute the segement of the strings returned from the other
  18. 'language--this is the DGROUP segment, and all string descriptors are found
  19. 'in this segment (even though the far string itself is elsewhere).
  20.  
  21. CALL StringAssign(VARSEG(a$), instrg1off, instrg1len, VARSEG(a$), VARPTR(a$), 0)
  22. CALL StringAssign(VARSEG(b$), instrg2off, instrg2len, VARSEG(b$), VARPTR(b$), 0)
  23.  
  24. ' Process the strings--in this case, add them.
  25. c$ = a$ + b$
  26.  
  27. ' Calculate the new output length.
  28. outstrglen = LEN(c$)
  29.  
  30. ' Transfer string output to a non-BASIC fixed-length string.
  31. CALL StringAssign(VARSEG(c$), VARPTR(c$), 0, VARSEG(c$), outstrgoff, outstrglen)
  32.  
  33. END SUB
  34.  
  35.