Object Model Reference for GUI Testing > Utility Objects > Referenced Information > Returning a String Value Using an Extern.Declare Statement

Returning a String Value Using an Extern.Declare Statement

String value types are not supported as return values for the Extern.Declare RetVal argument.

To return a string value, use a string out argument in the called procedure.

For example:

Instead of declaring the API as:

__declspec(dllexport) BSTR MyAPI (... some arguments...)

{

... // Some code that fills MyBstr

// For example:

// BSTR MyBstr

// wcscpy(MyBstr, L"ThisIsMyStr");

Return MyBstr;

}

Declare the API as:

__declspec(dllexport) void MyAPI (BSTR MyBstr, ... some arguments...)

{

... // Some code that changes MyBstr content

// For example:

// wcscpy(MyBstr, L"ThisIsMyStr");

Return;

}

To call API from UFT:

Extern.Declare micVoid, "MyAPI", "MyDLL.DLL", "MyAPI", micByRef + micWideString

Dim MyBSTR

' Creates the argument string.

MyBSTR = String(32)

Extern.MyAPI MyBSTR