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

calling c or fortran .dll from fortran

vader1000
Beginner
289 Views
i'm using cvf 6.6b. i am trying to make my application such that a user can had their own .dll function calls. to do this, i'd like to have a single .dll file that the user would always have, such as "some_dll.dll". i wrote a simple .dll in C and in fortran. In C, the prototype is as such:

extern "C" long __stdcall TEST_FUNCT(float TESTIN1, double TESTIN2, short TESTIN3, long TESTIN4, float *TESTOUT1, double *TESTOUT2, short *TESTOUT3, long *TESTOUT4)

In fortran, i need to specify this as _TEST_FUNCT@36... what? @36? yes, that's right... apparently the function type is long, so that adds another 4. however, if i do this function in fortran, the alias would be _TEST_FUNCT@32. obviously these conflict and i wouldn't be able to make a common call for both because one is @36 and the other is @32. is there a way around this?

one thing that is interesting is that VB will work as i want. if i have a fortran or C .dll, it can use the same function prototype and doesn't care if it is a C or fortran .dll, it runs perfectly. Can fortran be this forgiving?

related to this topic - is there a way to make a .dll call in fortran with OUT having to include a .lib file? ie, let's say the user wants to call a system api and they have just a .dll, how would they use this?
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
289 Views
What adds these 4 bytes is not the return value -- the culprit is TESTIN2, which is a double passed by value. On IA32, sizeof(long) == sizeof(int) == 4. But that's not what you want anyway -- Fortran arguments are always passed by reference (unless one plays with !DEC$ATTRIBUTES on Fortran side) regardless of their INTENT -- so, you need float& [const] TESTIN1, double& TESTIN2 etc.

VB has changed behaviour in this regard accross versions. IIRC, since VB6, everything is ByRef (as in Fortran) unless you specify ByVal explicitly.

related to this topic - is there a way to make a .dll call in fortran with OUT having to include a .lib file? ie, let's say the user wants to call a system api and they have just a .dll, how would they use this?

Yes. The keywords are LoadLibrary and GetProcAddress APIs(also require CVF Cray pointer extension). This has been discussed many times here so I wouldn't repeat -- please search the Forum. See also LOADEXP1 CVF sample, or MAPI sample on my home page.

Jugoslav
0 Kudos
Reply