X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



20913 Rate this article:
4.0

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);
}
Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »