<?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: DllImport, NullReferenceException in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815706#M45121</link>
    <description>&lt;DIV&gt;What's really weird is, if I change the order of the params around, it stops giving me an exception, but unfortuneately doesn't return any results either.&lt;/DIV&gt;</description>
    <pubDate>Fri, 14 Jan 2005 05:33:25 GMT</pubDate>
    <dc:creator>jacobya</dc:creator>
    <dc:date>2005-01-14T05:33:25Z</dc:date>
    <item>
      <title>DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815699#M45114</link>
      <description>&lt;DIV&gt;I apologize if this is not the proper place to post this question, but I'm getting pretty desperate after 3 days of trying to get this to work. I'm trying to call a function in a Fortran dll (for which I don't have the source) from a C# application. I have a working copy of a VB6 application that calls this dll, but I can't get my C# version to work.&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Here is the code I'm using:&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2"&gt;
&lt;P&gt;[DllImport(@"TrendFit.dll", EntryPoint="TrendFit"&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;)]&lt;/FONT&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" size="2"&gt;public&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;static&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;extern&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;int&lt;/FONT&gt;&lt;FONT size="2"&gt; trendfit(&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;int&lt;/FONT&gt;&lt;FONT size="2"&gt; lNPt,&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblX,&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblY,&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblSdY,&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;int&lt;/FONT&gt;&lt;FONT size="2"&gt; lNCoeff,&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblCoeff,&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblV,&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblVF);&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size="2"&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;private&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;void&lt;/FONT&gt;&lt;FONT size="2"&gt; button1_Click(&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;object&lt;/FONT&gt;&lt;FONT size="2"&gt; sender, System.EventArgs e)&lt;P&gt;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" size="2"&gt;int&lt;/FONT&gt;&lt;FONT size="2"&gt; lNPt = 30;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblX = 38222.5664467593;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblY = 6.99999999778811;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblSdY = 1;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;int&lt;/FONT&gt;&lt;FONT size="2"&gt; lNCoeff = 2;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblCoeff = 0;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblV = 0;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;double&lt;/FONT&gt;&lt;FONT size="2"&gt; dblVF = 0;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;int&lt;/FONT&gt;&lt;FONT size="2"&gt; result = 0;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;result = trendfit(&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; lNPt, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; dblX, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; dblY, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; dblSdY, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; lNCoeff, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; dblCoeff, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; dblV, &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;ref&lt;/FONT&gt;&lt;FONT size="2"&gt; dblVF);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;The 'trendfit' function is called, but the dblCoeff,
 dblV and dblVF values get set to NaN and I get a NullReferenceException when the calling method completes. The code above is similar to how the VB6 app calls the trendfit function, except the VB6 app was using LONG where I'm using INT because VB6 long is 4 bytes and long in .NET is 8.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Anyone have any idea what I'm doing wrong? Many thanks for your help&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 13 Jan 2005 08:46:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815699#M45114</guid>
      <dc:creator>jacobya</dc:creator>
      <dc:date>2005-01-13T08:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815700#M45115</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Remove "ref"-s from your DLL declaration and call statement and try to run the code. &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Sabalan.&lt;/DIV&gt;&lt;P&gt;Message Edited by Sabalan on &lt;SPAN class="date_text"&gt;01-13-2005&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;03:43 AM&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2005 16:16:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815700#M45115</guid>
      <dc:creator>sabalan</dc:creator>
      <dc:date>2005-01-13T16:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815701#M45116</link>
      <description>&lt;DIV&gt;Hi Sabalan, &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Thanks for your reply. I tried removing the "ref"s and it throws the NullReferenceException on the call to the the TrendFit function. The reason I put the "ref"s in there is because the VB6 app that works, passes all values ByRef. I even tried to get this to work from VB.NET instead of C# using the exact same syntax as the VB6 app but I still get the NRException. If I change the datatypes of the parameters around the parameters get altered differently, but I still get Nan in some results, that makes me think it has something to do with the size of the parameters that are being passed. &lt;/DIV&gt;</description>
      <pubDate>Thu, 13 Jan 2005 21:39:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815701#M45116</guid>
      <dc:creator>jacobya</dc:creator>
      <dc:date>2005-01-13T21:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815702#M45117</link>
      <description>In the DLL project, try setting the Libraries..Use Run-Time Libraries property to "Multi-threaded DLL" (not any of the Debug options.)</description>
      <pubDate>Thu, 13 Jan 2005 23:25:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815702#M45117</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2005-01-13T23:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815703#M45118</link>
      <description>&lt;DIV&gt;Unfortuneately, I don't have the source code for the DLL, so I can't change any of the properties. What I don't understand is why it would work in VB6 and not in .NET, would it be related to the datatypes? If I specify CallingConvention=CallingConvention.ThisCall, it doesn't throw a NullReferenceException (until I close the application), but doesn't modify any of the parameters.&lt;/DIV&gt;</description>
      <pubDate>Fri, 14 Jan 2005 01:29:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815703#M45118</guid>
      <dc:creator>jacobya</dc:creator>
      <dc:date>2005-01-14T01:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815704#M45119</link>
      <description>VB.NET seems to have some incompatibilities with the debug multithread DLLs - we have seen this in a handful of customer problems.  Same is true for any of the other managed code environments.</description>
      <pubDate>Fri, 14 Jan 2005 01:49:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815704#M45119</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2005-01-14T01:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815705#M45120</link>
      <description>&lt;DIV&gt;I'm running out of time and getting pretty desperate for a solution, so I'm considering taking the working VB6 code and rewriting it as a COM object and then tapping the COM object from .NET, I was saving this as a last resort, but it seems I'm at that point :) &lt;/DIV&gt;</description>
      <pubDate>Fri, 14 Jan 2005 02:08:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815705#M45120</guid>
      <dc:creator>jacobya</dc:creator>
      <dc:date>2005-01-14T02:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815706#M45121</link>
      <description>&lt;DIV&gt;What's really weird is, if I change the order of the params around, it stops giving me an exception, but unfortuneately doesn't return any results either.&lt;/DIV&gt;</description>
      <pubDate>Fri, 14 Jan 2005 05:33:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815706#M45121</guid>
      <dc:creator>jacobya</dc:creator>
      <dc:date>2005-01-14T05:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815707#M45122</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;You have a C# problem and I know almost nothing about C#. Butwhat yousay makes me think that there must be some problem with thevariable lengths. I have seen in som C# samples that people use a "F" after single precision constants, e.g. &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;MyVar=1.15F&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;I don't know if this is the same as to write:&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;float MyVar=1.15&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Maybe it would be worth to try a "D" after your double precision constants.&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Sabalan.&lt;/DIV&gt;
&lt;P&gt;Message Edited by Sabalan on &lt;SPAN class="date_text"&gt;01-14-2005&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:09 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Message Edited by Sabalan on &lt;SPAN class="date_text"&gt;01-17-2005&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;12:17 AM&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2005 17:07:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815707#M45122</guid>
      <dc:creator>sabalan</dc:creator>
      <dc:date>2005-01-14T17:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: DllImport, NullReferenceException</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815708#M45123</link>
      <description>&lt;DIV&gt;I figured it out, my problems were partly due to my lack of understaning of VB and partly because of differences between VB.NET and C#. In the VB6 example, I thought it was passing the first parameter in an array to the function, but I guess that's how VB passes an array, so it turns out I was passing doubles where I was supposed to be passing arrays of doubles. &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;After I finally clued into this, I got it working in VB.NET, but not C#. To get it to work in C#, I had to pass all arrays by value and not by ref. &lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Thanks for the help and hopefully my lack of VB knowledge didn't waste too much of anyone's time.&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Thanks again.&lt;/DIV&gt;</description>
      <pubDate>Fri, 14 Jan 2005 23:42:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/DllImport-NullReferenceException/m-p/815708#M45123</guid>
      <dc:creator>jacobya</dc:creator>
      <dc:date>2005-01-14T23:42:15Z</dc:date>
    </item>
  </channel>
</rss>

