Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner

call a DLL from Fortran - second part

Hi Steve, hi all,

you helped me not long ago for usind the function os_min in a differernt dll. That worked when I added the lib-File of the dll to my project (right click on the project and add) and used

!DEC$ ATTRIBUTES STDCALL :: OS_MIN

(!DEC$ ATTRIBUTES STDCALL, REFERENCE :: OS_MIN, if there were real arguments. not double precision)

in my code

and set the path to the lib.

 

But now (for my next application) I need a function in a dll but don't have a lib-file. I tried it by adding directly the dll-File. But it didn't work.

What I did wrong? Can you help me?

Greetings Olaf

0 Kudos
7 Replies
Highlighted
Black Belt

One can't link to a DLL, you

One can't link to a DLL, you need the .lib. You can create a .lib via a .def file as explained at https://adrianhenke.wordpress.com/2008/12/05/create-lib-file-from-dll/

Another choice is dynamic activation of the DLL - this is demonstrated in the compiler_f\DLL\DynamicLoad sample in the Intel Parallel Studio XE for Windows Sample Bundle.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner

Thank you Steve, I will try.

Thank you Steve, I will try.

0 Kudos
Highlighted
Beginner

Great Steve, it works, thank

Great Steve, it works, thank you

0 Kudos
Highlighted
Beginner

Steve,

Steve,

do I have to expand the USE statment in this context. This didn't work.

Greetings

Olaf

0 Kudos
Highlighted
Black Belt

You're referring to your

You're referring to your other thread on QuickWin? Post there and explain what "didn't work". USE has no direct relationship with DLL calls.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner

Hi Steve,

Hi Steve,

 

no I referring to this topic here (call a DLL from Fortran - second part).

I create this lib-File like you said.Without the USE it works, then I expand it and got while compiling the error "This name has not been declared as an array or a function.   [NPAR]" and for other variabliables the same error.

Ok, if you say, that USE has no direct relationship with a dll, maybe the namespace not insight dll. Can I check that?

greetings

 

Olaf

 

 

0 Kudos
Highlighted
Black Belt

There are two separate issues

There are two separate issues to be considered in using a routine that is exported from a DLL. Mixing the two issues and attempting to solve a problem by throwing in USE statements, whether those are needed or not, is not a good strategy.

If the implicit interface to the exported routine happens to be correct, you just have to make sure that the decorated name and calling conventions are matched between caller and callee when you link. If the implicit interface is not correct, Fortran requires that you provide an explicit interface to the routine at compile time. This may be done by providing an interface block or by adding a USE statement that names a module where the interface is provided. 

I must confess, Olaf, that I find your error descriptions to be quite vague and lacking many important details that are required before someone can recommend how to overcome a problem. In #4, you say " it works" and, in #5, "This didn't work" and, in both cases, the reader is left wondering what "it" and "works" were supposed to mean.

0 Kudos