当前位置: 动力学知识库 > 问答 > 编程问答 >

C# can't find an entry point in Fortran dll

问题描述:


I was given a working FORTRAN program and i have to write C# GUI for it (don't ask why). This program already has FORTRAN GUI, so i exctracted all the computing subroutines and put it into FORTRAN dll. This dll is built of 4 files: one static library, one FORTRAN77 file(.for) and two FORTRAN90 files(.f90). I've put all subroutines supposed to be called from within C# code into EXPORT.f90.

FORTRAN CODE:

MODULE MYVAR

REAL*8 LK

COMMON LK

END MODULE

SUBROUTINE SETLK(NEWLK)

!DEC$ ATTRIBUTES DLLEXPORT :: SETLK

USE MYVAR

REAL*8 NEWLK

LK = NEWLK

END

SUBROUTINE GETLK(LKOUT)

!DEC$ ATTRIBUTES DLLEXPORT :: GETLK

USE MYVAR

REAL*8, INTENT(OUT):: LKOUT

LKOUT = LK

END

Now i'm trying to call them in C#

[DllImport(@"MYDLL.dll", CharSet = CharSet.Ansi,

CallingConvention = CallingConvention.Cdecl,

EntryPoint="SETLK")]

public static extern void SETLK(ref double NEWLK);

[DllImport(@"MYDLL.dll", CharSet = CharSet.Ansi,

CallingConvention = CallingConvention.Cdecl,

EntryPoint="GETLK")]

public static extern void GETLK(out double LKOUT);

static void Main(string[] args)

{

double d1 = 1.234;

SETLK(ref d1);

double d2;

GETLK(out d2);

Console.WriteLine(d2.ToString());

}

I get EntryPointNotFoundException "Fail to find entry point 'SETLK' in 'MYDLL.dll'". What do i have to do to make it work?

Thanx

网友答案:

This thread suggests you need a .def file to declare the function exports (just as you used to in native Windows programming)

网友答案:

Look into your dll with a tool like PE explorer. It will tell you what exact functions are exported.

分享给朋友:
您可能感兴趣的文章:
随机阅读: