_DLL_call Function (Macro Constructor)

dll.h

#define _DLL_call(type,args,index) (*(type(*)args) _DLL_entry (index))

Constructs a function definition for a DLL call.

_DLL_call gets a void pointer to the location of the index-th exported symbol of the currently loaded DLL (using _DLL_entry), casts this pointer to a pointer to a function which returns type and which requires args as arguments, and dereferences it. This macro is usually used for accessing functions exported from the DLL. For example, suppose that the DLL contains the following declarations in the DLL interface section (see DLL_INTERFACE):

void foo (int, const char *);
int bar (long);
...
DLL_EXPORTS foo, bar
Then foo will get the index number 0, and bar will get the index number 1. To call foo from the main program (assuming that the DLL has been loaded sucessfully using LoadDLL) with arguments 123 and "foostr", you can principally do
_DLL_call (void, (int, const char *), 0) (123, "foostr");
But this is awkward, of course. So, to 'import' foo and bar from the DLL, you should use the following defines:
#define foo _DLL_call (void, (int, const char*), 0)
#define bar _DLL_call (int, (long), 1)
Then you can use foo and bar just as normal functions defined in the main program. For example:
foo (123, "foostr");
Principally, _DLL_call is quite similar to _rom_call, which constructs TIOS function calls instead of DLL function calls. But note that index in _DLL_call is an ordinary integer, which is not true for _rom_call.


See also: _DLL_call_attr, _DLL_reference, _DLL_glbvar