Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Comunicados
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29283 Discussões

entrypointnotfound exception when call dll from C# x64

John_Lee1
Principiante
1.182 Visualizações
All projects are on x64 platform.

dll is very simple

function mysqrt (x)
implicit none
real mysqrt
!DEC$ ATTRIBUTES DLLEXPORT :: mysqrt
real x
mysqrt = sqrt(x)
return
end function mysqrt

when call it in fortran, works very well:

real res,mysqrt
real dd
dd=9
res=mysqrt(dd)

when it was called from c#, a entrypointnotfound exceptione pops up:

class Program
{
[DllImport("dll.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern float mysqrt(ref float a);

static void Main(string[] args)
{
float dd = 9f;
float res;
res = mysqrt(ref dd);
}
}

Why? Any help will be apprecated!


0 Kudos
5 Respostas
Steven_L_Intel1
Funcionário
1.182 Visualizações
C# is case-sensitive, Fortran is not. Change the routine name in the C# code to MYSQRT and see if that helps.
onkelhotte
Novo colaborador II
1.182 Visualizações

Like Steve said, you have to cosider that C# is case sensitve.

To access a Fortran function/subroutine from both C# and Fortran, I use this approach on the C# side:

[bash][dllImport("my_dll.dll")]
private static extern void SETNAME(StringBuilder name);
[/bash]


And this is the Fortran part:

[bash]subroutine setName(name)
!DEC$ ATTRIBUTES DLLEXPORT :: setName
!DEC$ ATTRIBUTES ALIAS:'_SETNAME'::setName
  use sharedMemory
  character*12 name
  sharedName = name
end subroutine setName[/bash]

Markus

John_Lee1
Principiante
1.182 Visualizações
It works now. Thanks a lot.
Steven_L_Intel1
Funcionário
1.182 Visualizações
I very strongly recommend against including "decoration:" in an ALIAS directive, as this is platform-dependent. If you wanted to create a decorated name, use the DECORATE attribute.

However, I am a bit confused by Markus' example as _SETNAME would be the default external name on 32-bit Windows.

If you want to stay case-sensitive, consider using the C interoperability features. For example:

subroutine setName(name) bind(C,NAME="setName")

This will create the mixed case name setName (with appropriate decoration). If you omit the NAME= specifier, then the name is downcased.
onkelhotte
Novo colaborador II
1.182 Visualizações
You dont need the _SETNAME, but I included it to because my colleagues wondered why they had to use SETNAME in C#. So it is more "obvious", although you should know that. But some dont.

Markus
Responder