Microsoft KB Archive/89885

{| = Using LOAD and CALL with FoxPro for MS-DOS =
 * width="100%"|

ID: Q89885

The information in this article applies to:


 * Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6

SUMMARY
The text below describes the correct way to use a binary (.BIN) routine in FoxPro. The process is somewhat different from that used with Microsoft FoxBASE+ where an application can determine the length of a string parameter by searching for a null character. Because FoxPro allows null characters as part of a string, the technique used in FoxPro is different.

Calling Conventions
The DS:BX register pair provides the location of the passed parameter. If the parameter has the character data type, DS:BX points to a null- terminated character string. However, because a null character may be present in a FoxPro character string (as indicated above), finding a null character does not definitively denote the end of the string. If an application anticipates using embedded null characters, place the length of the string at the beginning of the string, as follows:

param = CHR(LEN(&quot;StringToPass&quot;))+&quot;StringToPass&quot; CALL test WITH param The CHR function stores the length of the string in one character. This method works for strings up to 255 characters long. The STR function can be used in place of the CHR function. If the parameter has the numeric data type, DS:BX points to an IEEE double-precision (8 byte) floating-point number.

If the parameter has the logical data type, DS:BX points to an 8-bit number that represents .F. with the value 0 and represents .T. with the value 1.

FoxPro can pass only one parameter to a binary routine. If more parameters are required, concatenate the parameters into a string and pass the string to the binary routine. The binary routine parses the string into its constituent parameters.

Changing the Value of the Parameter
The parameter of a binary routine may be either the result of an expression or the contents of a memory variable. If the parameter is generated by an expression, such as one of the following

CALL test WITH REPLICATE(&quot;Hello&quot;,2) + &quot;Goodbye&quot;

-or-

CALL test WITH x*(y+z) the DS register is set equal to the SS register. In other words, the result of the expression is stored in the FoxPro stack segment. It is neither useful nor advisable for a called routine to change the value of an expression passed as a parameter. However, if the parameter is the contents of a memory variable, such as the following

x = &quot;Hello&quot; CALL test WITH x the DS register does not equal the SS register. The routine may safely change the value of a memory variable. The updated value will be immediately available to the FoxPro application that called the routine. However, a binary routine cannot change the length of a character variable in the calling application. Placing a null character in the string does not shorten the variable, and adding characters to the end of a string can corrupt the FoxPro string pool. Additional reference words: FoxDos 2.00 2.50 2.50a 2.50b 2.60 KBCategory: kbprg KBSubcategory:
 * }