 |
_DLL_reference |
Function (Macro Constructor) |
#define _DLL_reference(type,index) ((type*const) _DLL_entry (index)) |
Returns a pointer to a global variable in a DLL.
_DLL_reference gets a void pointer to the location of the index-th exported symbol of the
currently loaded DLL (using _DLL_entry), then casts this pointer to a constant pointer
of type type. This macro is usually used for accessing arrays exported from the DLL.
For example, suppose that the DLL contains the following declarations in the DLL interface
section (see DLL_INTERFACE):
char foo[] = "FooString";
int bar[5] = {10, 20, 30, 40, 50};
...
DLL_EXPORTS foo, bar
Then foo will get the index number 0, and bar will get the index number 1.
To 'import' these two arrays from the DLL
(assuming that the DLL has been loaded sucessfully using LoadDLL),
you should use the following defines:
#define foo _DLL_reference (const char, 0)
#define bar _DLL_reference (int, 1)
Then you can use foo and bar just like normal arrays defined in the main program.
Note that the elements of foo can not be changed due to the const
qualifier
in the definition of foo (at least writing to it will trigger a warning).
However, you can access the elements of bar. For example:
printf ("%s %d", foo, bar[2]);
bar[2] = 100;
printf (" %d", bar[2]);
See also: _DLL_call, _DLL_call_attr, _DLL_glbvar