- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
Am trying to integrate a Fortran dll into a C# application with limited success.
I am using Intel Fortran Compiler 10.1.021 (IA-32) and a trial version of Visual Studio 2008.
I am able to pass parameters back and forth between the two projects and "step into" the Fortran dll when debugging.
However, when I try and do any I/O type operations in the Fortran dll a System.BadImageFormatException is thrown at the C# end. In the code snippets below uncommenting the "print *, num" cause the program to crash. doing any sort of IO will cause the program to crash with a System.BadImageFormatException error.
Here is a simplified version of the two code snippets:
C# Code:
// C# calling Fortran example namespace ConsoleApplication4 |
Fortran Code:
C! visualfortranDll1.f90 C ! Expose subroutine visualfortranDll1 to users of this DLL C ! Variables
C!
C! FUNCTIONS/SUBROUTINES exported from visualfortranDll1.dll:
C! visualfortranDll1 - subroutine
C!
subroutine visualfortranDll1(num)
C !
!DEC$ ATTRIBUTES DLLEXPORT::visualfortranDll1
!DEC$ ATTRIBUTES ALIAS:'visualfortranDll1'::visualfortranDll1
&nb
sp; REAL, INTENT(OUT) :: num
C ! Body of visualfortranDll1
num = num + 10 ! num = MOD(r1, 256.0)
!This line will throw a System.BadImageFormatException
! print *, num
end subroutine visualfortranDll1
P.S. Yes, this is a blatant rip off of the visualFortranDll1 example.
Thanks for getting me this far!
-Joe
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
Thanks for your prompt response, much appreciated, two things:
1. As stated previously "doing any sort of IO will cause the program to crash with a System.BadImageFormatException error", more importantly the C# throws a System.BadImageFormatExcpetion when doing somethings like:
open(1, file=filename)
close(1)
2. The C# actually is a console application, not sure what effect that has on things.
Cheers,
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Again thanks for the speed of the reply, but alas to no avail.
It was originally set to "Debug Multithread DLL" and I have changed it to "Multithread DLL", but nothing.
Is it conceivable that this is a "build platform" issue? I'm using 32-bit XP.
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes,
That is the same project that I have blatantly ripped off to illustrate my problem. Unfortunately, that project because of the calls to print (and even MOD) cause the BadImageFormatException. If those (IO) lines of code are removed the project runs as you would expect.
Thanks in advance,
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What's the value of the PATH environment variable on your system? I wonder if you have some 64-bit DLLs that are being found. Or, download DependencyWalker and use it to examine your DLL - does it report any seriosu problems?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So ran dependency walker and here is what it said:
1. Couldn't open MSJAVA.dll, although I'm not sure how important that is.
2. The output terminated with:
GetProcAddress(0x7C800000 [KERNEL32.DLL], "FlsAlloc") called from "MSCOREE.DLL" at address 0x790068DF and returned 0xFFBADD11.
Exited "CONSOLEAPPLICATION4.EXE" (process 0x450) with code -1073740791 (0xC0000409).
Couldthat imply that the FlsAlloc function could not be found in Kernel32.DLL? And then what does that mean?
A message board on Microsoft says, "It turns out that one of the library's I was statically linked to was using a different version of the CRT, so rebuilding it with the right version seems to have solved my problems". Do you think this could be related? And if so how do you rebuild with a different version?
Cheers,
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
steve, i downloaded the sample you attached. when i opened the "visualfortranDll1.sln", the visual studio 2005 that i have made a conversion of the project. this sample showed me somethings i didn't know before. so i tried to make a similar simple project to ensure that i understood the basic of things. unfortunately this didn't work.
when i focused, i saw that the fortran DLL part of the project generates tha DLL directly in the debug folder of the C# project part. this is automatically done every project generation. in the sample i created, the DLL is created in the folder of the fortran part of the project. i saw that a property called "output folder" is set to $(configurationname). i think that this is the property which manages all thing. so i wanted to ask you, is there any method to automate the generation of the DLL and its use from the C# project ? and is this all i have to know when i want to call fortran routines from a C# project ?
thanks steve for the help you're providing us with!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
and in such a case, what is the command line i have to add.
(i am sorry if my question seems eveident but i a m basically a mechanical engineer not a computer science engineer)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
![](/skins/images/98E68944C1FF703B8AC50091329B92AF/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page