View previous topic :: View next topic |
Author |
Message |
JDev
Joined: 09 Aug 2006 Posts: 3
|
Posted: Wed Aug 09, 2006 4:29 pm Post subject: Java-C-Fortran interoperability |
|
|
Hi,
I have developed a Fortran dll, created with FTN95 for .Net 2003. I call this dll from unmaneged Visual C++ code (exe) and I have no problems with both implicit (load time dynamic linking) and explicit (runtime) linking. The problems arose when a tried to call the above C++ code (but compiled as dll) from Java using the Java Native Interface and thus to have Java->C->Fortran interoperability. There are no compile or link errors, but I receive the following run-time error:
javaw.exe -Application error
The instruction at "0x424a5c64" referenced memory at "0x00000000". The memory could not be "written".
There is no error if I don't call the Fortran dll at all - I mean the Java-C part works. Have you any suggestions about the problem?
My second question is : I saw in FTN95 VisualCInteroperability example that __cdecl calling convention is assumed. How can I use __stdcall when caling Fortran functions from C++? I couldnt find anything about this in the documentation.
Best regards |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7933 Location: Salford, UK
|
Posted: Thu Aug 10, 2006 12:15 am Post subject: Java-C-Fortran interoperability |
|
|
In answer to your second question, you can put F_STDCALL before SUBROUTINE and FUNCTION in your Fortran code.
An alternative, if you are using FTN95 version 4.91, is to put /F_STDCALL on the FTN95 command line but this is a new feature and so it is not fully tested. |
|
Back to top |
|
|
JDev
Joined: 09 Aug 2006 Posts: 3
|
Posted: Fri Aug 11, 2006 12:32 pm Post subject: Java-C-Fortran interoperability |
|
|
Thanks for the answer. I've tried to put F_STDCALL before the SUBROUTINE and it worked.
I still can't resolve my first question. I think that JVM has problem with loading my Fortran dll which is called by my cpp wrapper dll (both Win 32). I've tried to do some debugging (Visual Studio) and I only saw that the Fortran library salflibc.dll was loaded at a relocated base address and was marked with red exclamation point.
Have I to link my Fortran dll with salflibc.lib, or this is done automaticaly?
Regards
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7933 Location: Salford, UK
|
Posted: Fri Aug 11, 2006 1:59 pm Post subject: Java-C-Fortran interoperability |
|
|
When you are creating the Fortran DLL, the linker finds salflibc.dll for you.
At runtime, salflibc.dll must be "visible" to the Fortran DLL. You could try puting a copy of both the Fortran DLL and salflibc.dll in the same folder as the executable. |
|
Back to top |
|
|
JDev
Joined: 09 Aug 2006 Posts: 3
|
Posted: Fri Aug 11, 2006 2:52 pm Post subject: Java-C-Fortran interoperability |
|
|
I have already put the dlls in the same folder as the executable, but there was no difference.
And what about Java - have you ever tried to call FTN dll from Java code through C wrapper dll? I ask this because I am trying to understand where is the problem - in me, in some Java - FTN incompatibility, or elsewhere in something having memory/pointer bugs. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7933 Location: Salford, UK
|
Posted: Sat Aug 12, 2006 12:58 am Post subject: Java-C-Fortran interoperability |
|
|
Sorry. I have not used Java in this way. |
|
Back to top |
|
|
|