Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

call a DLL from Fortran

Schwandt__Olaf
Beginner
2,335 Views

Hi there,

to call a DLL from another Fortran DLL in another topic Steve Lionel (Intel) wrote that there is an example from Intel, but I can't find.

Is someone able to help me?

Olaf

 

0 Kudos
14 Replies
Steve_Lionel
Honored Contributor III
2,335 Views

If you have the .lib that was generated when the DLL to be called was built, just add that .lib to your project, As long as both DLLs can be found by Windows where it looks for them (location of the EXE or in a folder named in the PATH environment variable), that's all you have to do.

0 Kudos
Schwandt__Olaf
Beginner
2,335 Views

 

Hi Steve,

I have a DLL without the lib from a third provider, but I know about the entry points. How can I deal that?

Olaf

0 Kudos
mecej4
Honored Contributor III
2,335 Views

Making an import library from a DLL can be performed using the following steps and the Visual Studio tools that are installed along with Intel compilers.

  1. Run dumpbin /exports <mydll.dll> > mydll.def OR, if you already know the list of names to be used, put that list into mydll.def.
  2. Edit mydll.def and follow the guidelines at https://msdn.microsoft.com/en-us/library/28d6s79h.aspx .
  3. lib /machine:i386 /def:mydll.def

After you have done these steps, you should have the import library mydll.lib, which you can link with your projects that will use the DLL.​

0 Kudos
Schwandt__Olaf
Beginner
2,335 Views

Hi Steve,

thank you very much.

And is that possible without an DEF-FILE (with somewhat like !DEC$ATTRIBUTES)?

Olaf

0 Kudos
Schwandt__Olaf
Beginner
2,335 Views
Hi Steve, I 've done as you first proposed, just adding to the project (with an own made dll - just drag and drop the lib-File to the project). But it dosn't work. VS dosn't recognize the function in the dll. How I call it? Do you have an example? Maybe I forgot something. Olaf
0 Kudos
Steve_Lionel
Honored Contributor III
2,335 Views

You may have the name of the entry point incorrect.

0 Kudos
gib
New Contributor II
2,335 Views

Did you do this?

dumpbin /exports mydll.dll > mydll.def

0 Kudos
Schwandt__Olaf
Beginner
2,335 Views

Hi Steve, hi all,

sorry for my late answer. I had a business trip. The name of my function is correct, I think.

Attached is the Dependency Walker output for my function. I call it x=os_min( ...)

Next I like to try dumpbin.exe. How I have to do that? In DOS? And ok, if nessary I try the DEF-File.

Regards

Olaf

By the way I work with Visual Studio 2017 Version 15.7.5 and Intel Parallel XE 2018 Update 3 Composer Edition for Fortran.

0 Kudos
Steve_Lionel
Honored Contributor III
2,335 Views

The @88 means that it is a STDCALL procedure. Try adding this in the procedure where you call it:

!DEC$ ATTRIBUTES STDCALL, REFERENCE :: OS_MIN

That there are 22 arguments means that it's likely you will need something more to pass the arguments correctly. How is os_min declared in the source for the DLL? I want to see the procedure declaration and the declarations of all its arguments.

I note that the routine name is lowercase, which means it wasn't built with default options in any Fortran compiler.

0 Kudos
Schwandt__Olaf
Beginner
2,335 Views

No, that are 11 arguments, because they are double precision.

After I adding your phrase, I have this:

error #6406: Conflicting attributes or multiple declaration of name.   [OS_MIN]       

 

and if I delete the convention double precision :: os_min there is this:

error #6404: This name does not have a type, and must have an explicit type.   [OS_MIN]

 

regards

 

Olaf

 

 

 

0 Kudos
Steve_Lionel
Honored Contributor III
2,335 Views

If the arguments are double precision, then remove ", REFERENCE" from the ATTRIBUTES line. Do you have another directive naming OS_MIN? You do also need a type declaration, as it would seem you have IMPLICIT NONE.

0 Kudos
Schwandt__Olaf
Beginner
2,333 Views

Hi Steve,

 

now it works!!!!! Thank you very very much.

 

Olaf

0 Kudos
Berrabah__Omar
Beginner
2,333 Views

Hi Steve

May I ask you some an advice to load rc.exe because it is not present on my PC.

My environment is VS2015 + parallel_studio_xe_2015_update6_online_setup.exe (for FORTRAN).

I need that to call a DLL Fortranin XExcel Office365 x64.

Thks in advance for your help.

Dr O.

 

0 Kudos
Steve_Lionel
Honored Contributor III
2,333 Views

rc.exe is part of VS2015's C++ support. Make sure you followed the steps in https://software.intel.com/en-us/articles/installing-visual-studio-2015-for-use-with-intel-compilers

0 Kudos
Reply