forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Java-C-Fortran interoperability

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
JDev



Joined: 09 Aug 2006
Posts: 3

PostPosted: Wed Aug 09, 2006 4:29 pm    Post subject: Java-C-Fortran interoperability Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu Aug 10, 2006 12:15 am    Post subject: Java-C-Fortran interoperability Reply with quote

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
View user's profile Send private message AIM Address
JDev



Joined: 09 Aug 2006
Posts: 3

PostPosted: Fri Aug 11, 2006 12:32 pm    Post subject: Java-C-Fortran interoperability Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Fri Aug 11, 2006 1:59 pm    Post subject: Java-C-Fortran interoperability Reply with quote

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
View user's profile Send private message AIM Address
JDev



Joined: 09 Aug 2006
Posts: 3

PostPosted: Fri Aug 11, 2006 2:52 pm    Post subject: Java-C-Fortran interoperability Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Sat Aug 12, 2006 12:58 am    Post subject: Java-C-Fortran interoperability Reply with quote

Sorry. I have not used Java in this way.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group