- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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!
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!
- Marcas:
- Intel® Fortran Compiler
Link copiado
5 Respostas
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
C# is case-sensitive, Fortran is not. Change the routine name in the C# code to MYSQRT and see if that helps.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
It works now. Thanks a lot.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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.
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.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
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
Markus

Responder
Opções do tópico
- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora