<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: String returned from C# to Fortran - problem in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896294#M79704</link>
    <description>&lt;DIV style="margin:0px;"&gt;If you are sending strings toa program written with any type of 'C'- language, do you not have to terminate each string with the null (CHAR(0)) character first? That's how C knows where the string ends. Any string length argument returned by Fortran must therefore include the terminating null character in the count so the C-side string length must match or exceed this length.&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Also, whenever a 'C'-type program sends a reference to a string, the string will be terminated with a null character too, so looking for the null characterlets you find the string's length. &lt;BR /&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 27 Nov 2008 10:05:03 GMT</pubDate>
    <dc:creator>anthonyrichards</dc:creator>
    <dc:date>2008-11-27T10:05:03Z</dc:date>
    <item>
      <title>String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896289#M79699</link>
      <description>&lt;P class="sectionBodyText"&gt;&lt;SPAN style="font-size: x-small;"&gt;I have an Intel Fortran program that calls a C# function. The C# function header is a follows, it takes "stringresourcekey" and returns "&lt;SPAN style="font-size: x-small;"&gt;stringresource" (1024 byte string) and two integers.&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;private void GetStringResource( &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;string stringresourcekey, &lt;BR /&gt;[In, Out, MarshalAs(UnmanagedType.LPArray, SizeConst = 1024)] byte[] stringresource, &lt;BR /&gt;ref int stringresourcelength_ansi, &lt;BR /&gt;ref int stringresourcelength_utf8)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;In Fortran, I call it like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt; GetStringResourceCallbackExternal(stringresourcekey,sStringResource,length_ansi,length_utf8)&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;Declarations are:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;STRONG&gt;&lt;FONT size="2" color="#0000ff"&gt;&lt;FONT size="2" color="#0000ff"&gt;
&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;character&lt;/P&gt;
&lt;STRONG&gt;&lt;FONT size="2" color="#0000ff"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/FONT&gt;&lt;/STRONG&gt;
&lt;P&gt;&lt;/P&gt;
&lt;SPAN style="font-size: x-small;"&gt; (len=*), &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;intent&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt;(in) :: stringresourcekey&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;character&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt; (len=1024) :: sStringResource,out_string&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;integer&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt; :: &amp;amp;&lt;BR /&gt;length_ansi, &amp;amp; &lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;! ANSI String length&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;length_utf8 &lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;! Effective String length when displayed with UTF-8 encoding&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN class="sectionBodyText" style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;This all works fine, the C# function is called, executes properly, and appears to return the intended values. Running in the debugger, I can see sStringResource,length_ansi,length_utf8 all returned with correct values and the intended string in sStringResource.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN class="sectionBodyText" style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;However when I try to use sStringResource, I have problems - if I write it to a file, the first part of it is garbage. If I try a simple assignment:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN class="sectionBodyText" style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;out_string = sStringResource&lt;/P&gt;
&lt;P&gt;then the program crashes with an access violation. Any ideas what I'm doing wrong (or not doing)?&lt;/P&gt;
&lt;P&gt;Mark Besley&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;
&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Nov 2008 06:08:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896289#M79699</guid>
      <dc:creator>Mark_Besley</dc:creator>
      <dc:date>2008-11-25T06:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896290#M79700</link>
      <description>&lt;DIV style="margin:0px;"&gt;In C# I use StringBuilder to exchange strings with Fortran.&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Here are two examples to get and put a character*4 value:&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;C#&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;
&lt;PRE&gt;[c-sharp]	public static void putusername(string value)
	{
		StringBuilder stringBuilderValue = new StringBuilder(value.Substring(0, System.Math.Min(value.Length, 4)));
		PUT_USERNAME(stringBuilderValue, 4);
	}

	public static string getusername()
	{
		StringBuilder stringBuilderValue = new StringBuilder(4);
		GET_USERNAME(stringBuilderValue, 4);
		return stringBuilderValue.ToString();
	}[/c-sharp]&lt;/PRE&gt;
&lt;PRE&gt;[c-sharp][/c-sharp]&lt;/PRE&gt;
&lt;PRE&gt;[c-sharp][/c-sharp]&lt;/PRE&gt;
&lt;PRE&gt;[c-sharp]Fortran:[/c-sharp]&lt;/PRE&gt;
&lt;PRE&gt;[c-sharp]&lt;PRE name="code" class="cpp"&gt;	subroutine put_dateiname(value)
		use globaleVariablen
		implicit none
		character*255 dateiname
		dateiname = value
	end subroutine put_dateiname
!
	subroutine put_username(value)
		use globaleVariablen
		implicit none
		character*4 username
		username = value
	end subroutine put_username[/c-sharp]&lt;/PRE&gt;
&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Nov 2008 07:45:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896290#M79700</guid>
      <dc:creator>onkelhotte</dc:creator>
      <dc:date>2008-11-25T07:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896291#M79701</link>
      <description>&lt;DIV style="margin:0px;"&gt;Why cant I edit my post?&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Here is the Fortran part again:&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;
&lt;PRE&gt;[cpp]	subroutine put_dateiname(value)
		use globaleVariablen
		implicit none
		character*255 dateiname
		dateiname = value
	end subroutine put_dateiname
!
	subroutine put_username(value)
		use globaleVariablen
		implicit none
		character*4 username
		username = value
	end subroutine put_username[/cpp]&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Markus&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Nov 2008 07:49:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896291#M79701</guid>
      <dc:creator>onkelhotte</dc:creator>
      <dc:date>2008-11-25T07:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896292#M79702</link>
      <description>&lt;DIV style="margin:0px;"&gt;Damn, I posted the wrong Fortran code... Its too early in the morning and I havent had any coffee yet ;-)&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;globaleVariablen is a module where username is declared as character*4. In the C# part you have to name the length of the character, so you write get_username(stringBuilderValue, 4),although the Fortran function doesnt have a second parameter.&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;FONT size="2"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;
&lt;PRE&gt;[cpp]	subroutine put_username(value)
		use globaleVariablen
		implicit none
		character*4 username
		username = value
	end subroutine put_username
!
	character*4 function get_username()
		use globaleVariablen
		implicit none
		getusername = username
	end function get_username[/cpp]&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Markus&lt;BR /&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 25 Nov 2008 07:56:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896292#M79702</guid>
      <dc:creator>onkelhotte</dc:creator>
      <dc:date>2008-11-25T07:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896293#M79703</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/408226"&gt;Mark Besley&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;
&lt;P class="sectionBodyText"&gt;&lt;SPAN style="font-size: x-small;"&gt;I have an Intel Fortran program that calls a C# function. The C# function header is a follows, it takes "stringresourcekey" and returns "&lt;SPAN style="font-size: x-small;"&gt;stringresource" (1024 byte string) and two integers.&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;private void GetStringResource( &lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;string stringresourcekey, &lt;BR /&gt;[In, Out, MarshalAs(UnmanagedType.LPArray, SizeConst = 1024)] byte[] stringresource, &lt;BR /&gt;ref int stringresourcelength_ansi, &lt;BR /&gt;ref int stringresourcelength_utf8)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;In Fortran, I call it like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt; GetStringResourceCallbackExternal(stringresourcekey,sStringResource,length_ansi,length_utf8)&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;Declarations are:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;character&lt;/P&gt;
&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;/STRONG&gt;
&lt;P&gt;&lt;/P&gt;
&lt;SPAN style="font-size: x-small;"&gt;(len=*), &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;intent&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt;(in) :: stringresourcekey&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;character&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt; (len=1024) :: sStringResource,out_string&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;integer&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt; :: &amp;amp;&lt;BR /&gt;length_ansi, &amp;amp; &lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;! ANSI String length&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;length_utf8 &lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;! Effective String length when displayed with UTF-8 encoding&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN class="sectionBodyText" style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;This all works fine, the C# function is called, executes properly, and appears to return the intended values. Running in the debugger, I can see sStringResource,length_ansi,length_utf8 all returned with correct values and the intended string in sStringResource.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN class="sectionBodyText" style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;However when I try to use sStringResource, I have problems - if I write it to a file, the first part of it is garbage. If I try a simple assignment:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN class="sectionBodyText" style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;out_string = sStringResource&lt;/P&gt;
&lt;P&gt;then the program crashes with an access violation. Any ideas what I'm doing wrong (or not doing)?&lt;/P&gt;
&lt;P&gt;Mark Besley&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;
&lt;/P&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;A further development - I changed nothing in the way that the calls were done and changed nothing at the C# end, but instead declared sStringResource as an array of 256 4-byte integers:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;STRONG&gt;
&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;use the same call: &lt;BR /&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt; GetStringResourceCallbackExternalstringresourcekey,sStringResource,length_ansi,length_utf8)&lt;/SPAN&gt;&lt;/P&gt;
&lt;SPAN style="font-size: x-small;"&gt;integer, &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;dimension&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt;(256) :: sStringResource,out_string&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;character&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt; (len=1024) :: mold,out_string1 &lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;out_string = sStringResource&lt;/P&gt;
&lt;P&gt;I can assign this to another integer array without getting an access violation, and better still I can transfer the data into a character variable and write it out and get the intended output as follows:&lt;/P&gt;
&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="color: #000000;"&gt;Any idea why this fails if I declare the sStringResource as character but works fine if I declare it as integer? Is there some subtle difference in the way the data is handled between the two types?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;FONT size="2"&gt;
&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;out_string1 =&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;
&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;transfer&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;(out_string,mold)&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;&lt;SPAN style="font-size: x-small; color: #0000ff;"&gt;write&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: x-small;"&gt;(unlis1,&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #800000;"&gt;&lt;SPAN style="font-size: x-small; color: #800000;"&gt;"(a)"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;)out_string1&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="color: #000000;"&gt;Mark Besley&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt; &lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2" color="#008000"&gt;
&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;
&lt;/P&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;FONT size="2"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small; color: #008000;"&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/SPAN&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2008 11:12:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896293#M79703</guid>
      <dc:creator>Mark_Besley</dc:creator>
      <dc:date>2008-11-26T11:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896294#M79704</link>
      <description>&lt;DIV style="margin:0px;"&gt;If you are sending strings toa program written with any type of 'C'- language, do you not have to terminate each string with the null (CHAR(0)) character first? That's how C knows where the string ends. Any string length argument returned by Fortran must therefore include the terminating null character in the count so the C-side string length must match or exceed this length.&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Also, whenever a 'C'-type program sends a reference to a string, the string will be terminated with a null character too, so looking for the null characterlets you find the string's length. &lt;BR /&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 27 Nov 2008 10:05:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896294#M79704</guid>
      <dc:creator>anthonyrichards</dc:creator>
      <dc:date>2008-11-27T10:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896295#M79705</link>
      <description>&lt;P class="MsoNormal" style="margin: 0cm 0cm 0pt;"&gt;&lt;SPAN style="font-size: small; font-family: Arial;"&gt;Hallo everybody&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="MsoNormal" style="margin: 0cm 0cm 0pt;"&gt;&lt;SPAN style="font-size: small; font-family: Arial;"&gt;It looks like you are familiar with calling C# from Fortran. Can you please help me with my project I attached?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="MsoNormal" style="margin: 0cm 0cm 0pt;"&gt;&lt;SPAN style="font-size: small; font-family: Arial;"&gt;Im not able link C# dll. I created interface (suppressed in code) but it doesnt work. In help is written that for .NET dll is necessary use Module Wizard for creating interface. But when I used this Wizard no interfaces crated (see. ShowNumberInterface.f90). &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="MsoNormal" style="margin: 0cm 0cm 0pt;"&gt;&lt;SPAN style="font-size: small; font-family: Arial;"&gt;Can you please tell me what is necessary for making right Fortran  C# mixed language solution?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="MsoNormal" style="margin: 0cm 0cm 0pt;"&gt;&lt;SPAN style="font-size: small; font-family: Arial;"&gt;I use VS2003.NET and IVF 10.1.019.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="MsoNormal" style="margin: 0cm 0cm 0pt;"&gt;&lt;SPAN style="font-size: small; font-family: Arial;"&gt;Jiri&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Nov 2008 12:42:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896295#M79705</guid>
      <dc:creator>pieterj</dc:creator>
      <dc:date>2008-11-27T12:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896296#M79706</link>
      <description>&lt;DIV style="margin:0px;"&gt;Ops, and nowthis file:o)&lt;/DIV&gt;</description>
      <pubDate>Thu, 27 Nov 2008 12:46:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896296#M79706</guid>
      <dc:creator>pieterj</dc:creator>
      <dc:date>2008-11-27T12:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896297#M79707</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/209155"&gt;pieterj&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;
&lt;DIV style="margin:0px;"&gt;Ops, and nowthis file:o)&lt;/DIV&gt;
&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;I do not know C#, but I do know that if you want a Fortran program to call a function in a DLL, then&lt;/P&gt;
&lt;P&gt;a) you must make the function or symbol for the functionvisible to users of the DLL, and&lt;BR /&gt;b) In your Fortran code, you must use the correct symbol for the function you wish to access in the DLL, possibly using a compiler flag such as ALIAS, and&lt;BR /&gt;c) In your Fortran code, you must mark that symbol as to be IMPORTED from a dll using a compiler flag such as DLLIMPORT,&lt;BR /&gt;d) You must also, in your Fortran, ensure that the calling convention agrees with the C# one (e.g. are the arguments supplied by value or reference (i.e. address)&lt;/P&gt;
&lt;P&gt;In your C# code,&lt;/P&gt;
&lt;PRE&gt;[cpp]using System;
using System.Windows.Forms;

namespace prijimac
{
	public class Class1
	{

		public static void ShowNumber(int a, int b)
		{
			MessageBox.Show("a=" + a.ToString()+ " b=" + b.ToString());
		}

	}
}
[/cpp]&lt;/PRE&gt;
&lt;P&gt;There are no symbols exported, correct?. Thus, as far as I can see from your zipped archive, there is no export library (.LIB) of symbols generated and supplied along with your C# DLL, so there is no way for your Fortran program to be given the details as to what and whereare the symbols that you wish to reference in your Fortran code (normally you would include the .LIB in your Fortran project to do this). This shortcoming has to be rectified first before you stand a chance of calling functions in your DLL, IMO.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Nov 2008 14:08:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896297#M79707</guid>
      <dc:creator>anthonyrichards</dc:creator>
      <dc:date>2008-11-27T14:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896298#M79708</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;P&gt;I agree with Anthony's assessment.&lt;/P&gt;
&lt;P&gt;Exporting from a C# DLL is nonstandard and has been discussed (my me) here on this forum some time ago.&lt;/P&gt;
&lt;P&gt;Gerry&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Nov 2008 15:13:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896298#M79708</guid>
      <dc:creator>g_f_thomas</dc:creator>
      <dc:date>2008-11-27T15:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896299#M79709</link>
      <description>&lt;DIV style="margin:0px;"&gt;Essentially, you have to reproduce in C# what is given below as the code for a C++ DLL (given the name mycdll for example) containing one function MyCDllRoutine. Note that given the calling convention used, this will export a symbol &lt;A href="mailto:_MyCDllRoutine@8"&gt;_MyCDllRoutine@8&lt;/A&gt; in the generated symbol table mycdll.lib (note the preservation of case, theadded leading underscore and thedecoration @8). The Fortran code to produce a Console application (so that you can write to the screen) that calls the DLL is given below the C++ code. In order for the Fortran program to work, the file mycdll.lib must be added to the Fortran project and the mycdll.dll code added to the folder containing the Fortran executable.&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;
&lt;PRE&gt;[cpp]// mycdll.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"

// myDLL.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "iostream.h"
#include "stdlib.h"

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
      )
{
    return TRUE;
}

   extern "C" __declspec(dllexport)  void  __stdcall MyCDllRoutine(int a, int b) ;


// MAIN ENTRY FUNCTION
void  __stdcall MyCDllRoutine (int a, int b)
{
	char achar[10], bchar[10], str[80];

itoa(a,achar,10); 
itoa(b,bchar,10);
strcpy(str," a = ");
strcat(str,achar);
strcat(str,", b = ");
strcat(str,bchar);
cout &amp;lt;&amp;lt;" Entered MyCDllRoutine in the C++ DLL"&amp;lt; [/cpp]&lt;/PRE&gt;
&lt;PRE&gt;[cpp]Fortran Code:[/cpp]&lt;/PRE&gt;
&lt;PRE&gt;[cpp]&lt;PRE name="code" class="cpp"&gt;!****************************************************************************
!
!  PROGRAM: testmycdll
!
!  PURPOSE:  Entry point for 'Hello World' sample console application to access
!			 a routine held in a Win32 Dynamic link library compiled from C++ code
!
!****************************************************************************

	program testmycdll

implicit none
!
INTEGER I,J

       INTERFACE
       SUBROUTINE MYCDLLROUTINE (I,J)

       !DEC$ ATTRIBUTES DLLIMPORT :: MYCDLLROUTINE
       !DEC$ ATTRIBUTES STDCALL :: MYCDLLROUTINE
       !DEC$ ATTRIBUTES ALIAS:'_MyCDllRoutine@8' :: MYCDLLROUTINE
	   INTEGER I,J

       END SUBROUTINE MYCDLLROUTINE
       END INTERFACE

 print *, 'Hello World'
 I=10
 J=25

       CALL MYCDLLROUTINE(I,J)

	end program testmycdll
[/cpp]&lt;/PRE&gt;
&lt;BR /&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 27 Nov 2008 17:24:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896299#M79709</guid>
      <dc:creator>anthonyrichards</dc:creator>
      <dc:date>2008-11-27T17:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: String returned from C# to Fortran - problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896300#M79710</link>
      <description>&lt;DIV style="margin:0px;"&gt;The following was somehow chopped off the end of the C++ code:&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;
&lt;PRE&gt;[cpp]cout &amp;lt;&amp;lt;" Entered MyCDllRoutine in the C++ DLL"&amp;lt; [/cpp]&lt;/PRE&gt;
&lt;PRE&gt;[cpp]MessageBox(HWND_DESKTOP,str,"Two numbers sent to C++ DLL",MB_OK);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;[/cpp]&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 27 Nov 2008 17:28:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/String-returned-from-C-to-Fortran-problem/m-p/896300#M79710</guid>
      <dc:creator>anthonyrichards</dc:creator>
      <dc:date>2008-11-27T17:28:19Z</dc:date>
    </item>
  </channel>
</rss>

