Returning Interface References From DLL Functions

Applies to TestComplete 15.70, last modified on December 17, 2024

Functions located in dynamic link libraries may return an IDispatch, IUnknown or another interface reference as a result value. This topic describes some specifics of calling such functions from DLLs created with Visual C++ and Delphi.

Suppose, we have the following declarations of Visual C++ and Delphi functions that return an IDispatch reference value:

Visual C++

IDispatch __stdcall Test();

Delphi

function Test(): IDispatch; stdcall;

In the stdcall calling convention, the function’s result is passed via the CPU’s EAX register. However, Visual C++ and Delphi generate different binary code for these routines. Visual C++ stores the pointer to an IDispatch return value in the EAX register, as it is adopted in the stdcall convention. The specific of Delphi is that it returns the pointer to an IDispatch value via the stack.

TestComplete uses the same calling conventions as those adopted by Visual C++. So, you are able to call a C++ function declared in the described way from your scripts, but you are not able to call a Delphi routine that is declared as it was described above. To be able to obtain an IDispatch value from your Delphi routine, declare it in the following manner:

Delphi

procedure Test(var ResultObjRef : IDispatch); stdcall;

See Also

Calling DLL Functions From Tests
Calling DLL Functions From Tests - Overview

Highlight search results