PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Return string from Fortran Dll back to C#.

Reply

Return string from Fortran Dll back to C#.

 
Thread Tools Rate Thread
Old 03-07-2003, 11:45 AM   #1
Alex Dong
Guest
 
Posts: n/a
Default Return string from Fortran Dll back to C#.


Dear all:
My C# program need a string returned from a Fortran Dll.
The Fortran Dll is like this:

SUBROUTINE REDO(s)
!DEC$ ATTRIBUTES DLLEXPORT::REDO, C
CHARACTER*(*) s
!DEC$ ATTRIBUTES REFERENCE :: s
s = 'Let them talk, now!'C
END

And I use C# PInvoke to call it, the client code like this:

public class BackString
{
[DllImport(@"BackString.dll",
EntryPoint="REDO")]
public static extern void REDO(string output);
}

string output = "";
BackString.REDO(output);

When I call this, I got an NullReferenceException, can anybody here explain
why? and how could I return the string?

I also tried to return the value as "Return" but have the same problem. The
..NET Framework's PInvoke example to use C's return string works fine, but I
just can't make the Fortran work.

Thank everybody and hope I could get some reply.

Regards
Alex


  Reply With Quote
Old 04-07-2003, 01:02 PM   #2
Vadim Melnik
Guest
 
Posts: n/a
Default Re: Return string from Fortran Dll back to C#.

Hi,

> And I use C# PInvoke to call it, the client code like this:
>
> public class BackString
> {
> [DllImport(@"BackString.dll",
> EntryPoint="REDO")]
> public static extern void REDO(string output);
> }
>
> string output = "";
> BackString.REDO(output);
>
> When I call this, I got an NullReferenceException, can anybody here

explain
> why? and how could I return the string?
>


StringBuilder should be used for string out arguments. How about the
following in C# ?

public static extern void REDO(StringBuilder output);

.....

StringBuilder sb = new StringBuilder(1024);
REDO(sb);
Console.WriteLine(sb);


...
Regards,
Vadim




  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off