DLL Example: Passing String Parameters by Reference

When you pass a variable to a function by reference, the address of the variable is passed. If the function changes the value of the passed variable, it changes within the calling program as well as in the function.

In the module from which the sample code was drawn, the GetTempPath function was exported from Kernel32.dll, which was inserted under the program module's Libraries submodule as shown below.

The sample code below shows how to pass a string variable argument sString1024 (defined as a fix size String:1024) to a sBuffer Var String parameter. It uses a fixed size string so that the size of the buffer that holds the string is pre-allocated. On return, ATEasy sets the string length according the value indicated by the null-terminated string. That is, the number of characters preceding the first zero character is the number of characters in the string.

! example to use a fixed string with 1024 size (String :1024)
if GetTempPath(1024, sString1024)<1

TestStatus=FAIL

endif

if Len(sString1024)<1

TestStatus=FAIL

endif


! example to use a regular string

! we need to set its length before we call the procedure

s=spaces(1024)

if GetTempPath(1024, s)<1

TestStatus=FAIL

endif

if Len(s)<1

TestStatus=FAIL

endif