Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

Passing a string to Fortran

$
0
0

I've had quite a lot of luck interoperating between Fortran and C# using Robert Giesecke​'s "Unmanaged Exports" library.  However, one of the things I haven't been able to achieve yet is sending a string from C# to Fortran.  The worst of it is that I get no indication of what's wrong.  My Fortran application just crashes.  From all the research I've done, it would seem to me the following should work:

C# "sender"

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct MyStruct
{
    [MarshalAs(UnmanagedType.LPStr, SizeConst = 200)]
    public string Title;
    public int SourceNode;
    public int EndNode;
}

Fortran "receiver"

type, bind(c) :: MyFirstStruct
    character(200, kind=C_CHAR) :: Title
    integer :: SourceNode
    integer :: EndNode
end type

When I run this I get the following:

forrtl: severe (172): Program Exception - exception code = 0x4352 (17234)

Any help or ideas would be much appreciated!

Brad.

P.S.  I can include the entire source for both sides, if it helps - just let me know.


Viewing all articles
Browse latest Browse all 5691

Trending Articles