20903
How to Export Symbols in a Dynamically Loadable Library
How to Export Symbols in a Dynamically Loadable Library in Windows.
All DLLs contain symbols that specify entry points into the library. In lay terms these symbols are the names of functions in "C" or subroutines or functions in Fortran. For IDL to properly access these functions or subroutines, the entry points must be specified during the build of the library. Specifying these symbols causes the symbols to be exported. There are two different methods for specifying these symbols.
The first method is to create a "library name".def file in the following format:
EXPORTS
TestOne
TestTwo
TestThree
TestFour
The symbols TestOne, TestTwo, TestThree, and TestFour will all be exported in the DLL and IDL will be able to locate these entry points when CALL_EXTERNAL is called.
Visual Studio's LINK.EXE provides a a linker option /DEF:filename.def for this purpose. For more information about how the linker uses a *.def file please consult your linker's documentation.
Another method for exporting symbols in "C" is to define symbols in "C" source code using the Visual C++ __declspec macro. An external export definition file is not needed in this case. The Example Code section illustrates the use of the __declspec macro. The simple "C" function test is declared to be exported in the DLL. IDL can then locate the entry point 'test' in the DLL when the CALL_EXTERNAL function is called.
This example simply calculates the sum of the elements (like TOTAL).
From IDL you can call it like this.
IDL> a=dindgen(10)
IDL> help, call_external('text.dll','test',/d_value, a, n_elements(a), /cdecl)
DOUBLE = 45.000000
The "C" is needed if you are using MS Visual C++ and need to specify standard C calling convention. If the file name extension is .c and not .cpp, then Visual Studio will default to C mode and the "C" is not needed.
extern "C" __declspec(dllexport) double test(int argc, char **argv)
{
double sum, *d;
int n, i;
n=*((int *) argv[1]);
d=(double *) argv[0];
for (sum=i=0;i return(sum);
}