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

VS2005 C#.Net Calling Fortran 9.1 dll

jeltz
初學者
1,043 檢視
Going in circles on this stupid test program. I create a fortran dll with subroutine called test, and use .NET interop services in C# to [DllImport("fortrandll.dll")], but when calling the fortran subroutine from C#, get the runtime debug exception "unable to find entry point for test". This is supposed to be the way to call unmanaged dll functions from managed C#.Net is it not?
Is this just thatI have not got calling conventions right? (default optionsused at either end, but setting numerous permutations of calling options does not work either. Any thoughts?
Jeltz

Message Edited by jeltz on 05-19-200606:09 AM

0 積分
5 回應
Steven_L_Intel1
1,043 檢視
We'd need to see more of the code. Keep in mind that C# is case-sensitive and Fortran, by default, upcases all of the routine names. Also, I'm uncertain if C# requires the stdcall calling mechanism for dllimport routines.
jeltz
初學者
1,043 檢視

Doh...forgot to add !DEC$ ATTRIBUTES DLLEXPORTto fortran function so little wonderC# could not find it....Sorry, I will crawl back under my rock now. Just goes to show that error messages sometimes say what they mean...Jeltz

jeltz
初學者
1,043 檢視
OK Steve now explain this one!
the following code fails in the C# call with:
Unable to load DLL 'testit.DLL': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
subroutine testit()
integer*4 NY
!DEC$ ATTRIBUTES DLLEXPORT::testit
integer*4 i
real*8 ma(55)
ma(1)=1
ma(55)=1
do i=1,54
ma(i)=1
end do
end subroutine testit
BUT with one minor change, the followingexecutes just fine:
subroutine testit()
integer*4 NY
!DEC$ ATTRIBUTES DLLEXPORT::testit
integer*4 i
real*8 ma(55)
ma(1)=1
ma(55)=1
do i=1,54
ma(10)=1
end do
end subroutine testit
This is the managed C# code doing the calling
[DllImport("testit.dll")]
private extern static void TESTIT();

public static void test()
{
TESTIT( );
}
jeltz
初學者
1,043 檢視

OK found the answer; The one change to the code made it go look for a fortran support dll which it could not find. had to find the right fortran dll in the 9.1 lib directory and put it in the right place.

Why are these ancilliary fortran dlls not in the interopdll hunt path for .Net 2.0 ? and since the fortan compiler knows it need them (eventually at runtime) why can it not make them a project dependency?

Jeltz

Steven_L_Intel1
1,043 檢視
When you installed the compiler, you were asked if you wanted to modify the system environment variables and warned that if you didn't, programs that depend on the Fortran DLLs won't run. You can manually add the path to the Fortran BIN folder to PATH.

I'm not familiar with DLLs as project dependencies or "interop dll paths". I'll look those up.
回覆