PC Review


Reply
Thread Tools Rate Thread

Return string from Fortran Dll back to C#.

 
 
Alex Dong
Guest
Posts: n/a
 
      3rd Jul 2003
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
 
 
 
 
Vadim Melnik
Guest
Posts: n/a
 
      4th Jul 2003
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to determine what language a c# string is written in? is there any C# method to take a string and return what language it is in? e.g. english, hindi, spanish, etc. DR Microsoft Dot NET Framework 3 30th Jan 2008 05:39 PM
Late binding to a FORTRAN DLL routine with a string paramter =?Utf-8?B?TWFyZWs=?= Microsoft Dot NET 1 24th Oct 2007 08:24 AM
Date string problem in query string when posting back =?Utf-8?B?SnVsaWEgQg==?= Microsoft ASP .NET 5 29th Aug 2007 04:08 PM
string to byte[] back to string + Compression Failed! jeremyje@gmail.com Microsoft C# .NET 5 10th Feb 2007 08:48 PM
Convert a string to Ascii codes and then back to string again Kai Bohli Microsoft C# .NET 11 8th Jul 2004 04:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:07 PM.