Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29329 Discussions

CVF program calling a DDL in CVF

denara
Beginner
811 Views
Hi, hope anayone can help me.
I wrote a CVF program (console application) that uses some functions and subrotines ofa DLL also written in CVF. These functions/subroutines are not always used, just in some specific calculations.
I noticed that, when staring the main program the DLL is also loaded to memory, even if the functions/subroutines are never used. Thus, the DLL is unloaded only when the main program exits.
Questions:
1) Is there any way to load the DLL only when it is actually to be used by the main program?
2) Is there a way to unload the DLL when it is no more needed?
Thanks.
0 Kudos
4 Replies
Steven_L_Intel1
Employee
811 Views
There are two ways to defer loading a DLL. The one you want is to call LoadLibrary to load the DLL, GetProcAddress to get the routine address, and use the extension that allows calling through a pointer to call the routine. You can then call FreeLibrary to unload the DLL. See the DLLLOADEXP1 sample provided with CVF.

There is also a way to defer the loading until you do a call that does not require coding changes, using a linker feature called "delayed loading", but you can't then unload the DLL.
0 Kudos
denara
Beginner
811 Views
Thanks, but I still have some questions:
1) In the main CVF program I must include the LIB associated to the DLL, otherwise I get some "unsolved external" error messages. I doing so, I understand the DLL will be automatically loaded when the main program starts.
2) So, I supose LOADLIBRARY will not apply here. Am I right?
3) If so I still dont know if it is really possible to defer loading the DLL.
Thanks again.
0 Kudos
Steven_L_Intel1
Employee
811 Views
If you use LoadLibrary, you do not need to link against the .LIB. However, the coding of the call is slightly more complicated. Again, the sample I pointed you to illustrates this technique in detail.
0 Kudos
denara
Beginner
811 Views
Now I got it to work fine.
Thanks.
0 Kudos
Reply