CALL DWORD statement

Purpose

Invoke a Sub or Function indirectly.

Syntax

CALL DWORD TargetPtr
CALL DWORD TargetPtr USING abc([arguments]) [TO result_var]

Remarks

CALL DWORD is an essential ingredient for implementing run-time (explicit) dynamic linking of DLLs, rather than the more common load-time (implicit) linking.  This provides a way of constructing calls to APIs and DLLs that may not be present in all versions of Windows.  This technique ensures that an application can start up successfully, even if Windows cannot resolve the location of the API or DLL function.

The first (simplified) form of CALL DWORD may be used if the target Sub/Function takes no parameters and offers no return value.  It also requires STDCALL ( SDECL ) calling conventions, which is used by the vast majority (99%+) of import procedures.  In all other cases, you must use the second form, with a USING clause to define the signature of the target Sun/Function.

TargetPtr

A Double-word, Long-integer, or pointer variable that contains the address of the entry point of a procedure (Sub or Function).  If the target Sub/Function is located in the same module, you can retrieve the address with the CODEPTR function.  If it's located in an external DLL, use IMPORT ADDR to load it and get the address.

USING

This option is used to define a model procedure declaration which matches all of the calling conventions desired to be used to invoke the target Sub/Function.  For example, the following two calls to the function MySubCall are equivalent:

DECLARE SUB MySubCall
DIM PtrMySubCall AS DWORD
PtrMySubCall= CODEPTR(MySubCall)
[statements]
CALL MySubCall
CALL DWORD PtrMySubCall USING MySubCall

arguments

An optional, comma-delimited list of variables, expressions, and constants to be passed to the procedure as parameters.  In the CALL DWORD context, enclosing parentheses are required.  The number and type of parameters passed must agree with the arguments of the procedure named by the USING clause.  See CALL for more information on parameter passing methods.

TO result_var

When calling a Function which returns a value, the TO keyword offers a way to assign the function return value to result_var.

Restrictions

Thread Functions and Callback Functions may not be invoked with CALL DWORD.  The DECLARE model for the USING clause may not specify a LIB or IMPORT option.

See also

CALL, CODEPTR, DECLARE, FASTPROC, FUNCTION/END FUNCTION, IMPORT, SUB/END SUB, THREAD CREATE