String Parameters - C/C++ DLL Call Parameters

String Parameters

When using string parameters, use the C String Buffer or Unicode String Buffer type when you want the function to be able to change the contents of the argument in TestStand. Use the C String or Unicode String type when the DLL function does not modify the argument. You can pass a literal string, a TestStand string property, or an expression that evaluates to a string as the value of a string parameter.

The following settings are available in the Data Type ring control when you select String for the category type.

String Data Type Setting Equivalent C Data Type
C String const char *
C String Buffer char[]
Unicode String const wchar_t * or cont unsigned short *
Unicode String Buffer wchar_t[] or unsigned shortp[]

If you specify one of the string buffer types, the C/C++ DLL Adapter copies the contents of the string argument and a trailing zero element into a temporary buffer before calling the function. Specify the minimum size of the temporary buffer in the Buffer Size control. If the string value is longer than the buffer size you specify, the C/C++ DLL Adapter resizes the temporary buffer so it is large enough to hold contents of the string argument and the trailing zero element. After the DLL function returns, TestStand copies the value from the temporary buffer back to the string argument.

Note When you overwrite the last character in a string buffer, the C/C++ DLL Adapter automatically allocates an extra character to prevent memory corruption. Consequently, TestStand does not detect a buffer overrun error when you exceed a string buffer size by only one character.

If you specify the C String or Unicode String type, the C/C++ DLL Adapter passes the address of the actual string directly to the function without copying it to a buffer. The code module must not change the contents of the string.

Note You can pass NULL to a String pointer parameter by passing an empty object reference or the constant Nothing . Do not pass the constant 0 .

See Also

Mapping Parameters