- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
C# is case-sensitive, Fortran is not. Change the routine name in the C# code to MYSQRT and see if that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It works now. Thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page