<?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: Error with the IFX compiler when I call a Fortran subroutine from C# in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686655#M175667</link>
    <description>&lt;P&gt;Hello Ron&lt;/P&gt;&lt;P&gt;I've opened the IFX DLL with Notepad and the header says:&lt;/P&gt;&lt;P&gt;MZx &amp;#1; &amp;#4; @ x &amp;#14;&amp;#31;º&amp;#14; ´ Í!¸&amp;#1;LÍ!This program cannot be run in DOS mode.$ PE d†&amp;#11; .ù&amp;#17;h ð&lt;/P&gt;&lt;P&gt;The IFORT DLL also says&lt;/P&gt;&lt;P&gt;PE d†&lt;/P&gt;&lt;P&gt;Is there anything wrong?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Apr 2025 10:27:16 GMT</pubDate>
    <dc:creator>dj1967</dc:creator>
    <dc:date>2025-04-30T10:27:16Z</dc:date>
    <item>
      <title>Error with the IFX compiler when I call a Fortran subroutine from C#</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686351#M175651</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm using Intel Fortran 2024.1 and Visual Studio 2022 Professional.&lt;/P&gt;&lt;P&gt;When I call a basic Fortran subroutine from C# I don't get any errors get with the IFORT compiler. However when I switch to the IFX compiler, I get the following error:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)&lt;BR /&gt;at CallDLL_64.Program.MYSUB64(Int32&amp;amp; ic, Int32&amp;amp; idiag, String filename, Int32 L1)&lt;BR /&gt;at CallDLL_64.Program.Main(String[] args)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Fortran code is:&lt;/P&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;MODULE DllInterface&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp;IMPLICIT NONE&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;CONTAINS&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;!DEC$ ATTRIBUTES DLLEXPORT::MYSUB64&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;!DEC$ ATTRIBUTES ALIAS : "MYSUB64" :: MYSUB64&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;!&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;SUBROUTINE MYSUB64(ic, idiag, filename)&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IMPLICIT NONE&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; INTEGER*4, INTENT(INOUT)&amp;nbsp; &amp;nbsp; &amp;nbsp;:: ic, idiag&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; CHARACTER*(*)&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; :: filename&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;!&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;!--------------------------- Body of program&amp;nbsp; --------------------------&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;!&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;!&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ic = 1&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; idiag = 2&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; RETURN&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;END&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;END MODULE DllInterface&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The C# code is&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using System.Runtime.InteropServices;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;namespace CallDLL_64&lt;BR /&gt;{&lt;BR /&gt;class Program&lt;BR /&gt;{&lt;BR /&gt;[DllImport(@"..\\..\\..\\bin\\x64\\myDLL.dll", CallingConvention = CallingConvention.Cdecl)]&lt;BR /&gt;public static extern void MYSUB64(ref int ic, ref int idiag, string filename, int L1);&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;BR /&gt;static void Main(string[] args)&lt;BR /&gt;{&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;int ic;&lt;BR /&gt;int idiag;&lt;BR /&gt;string X = "Hello";&lt;BR /&gt;int L1;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;try&lt;BR /&gt;{&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;ic = 0;&lt;BR /&gt;idiag = 0;&lt;BR /&gt;L1 = X.Length;&lt;BR /&gt;MYSUB64(ref ic, ref idiag, X, L1);&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;Console.WriteLine(ex.ToString());&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 15:03:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686351#M175651</guid>
      <dc:creator>dj1967</dc:creator>
      <dc:date>2025-04-29T15:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error with the IFX compiler when I call a Fortran subroutine from C#</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686359#M175652</link>
      <description>&lt;P&gt;The ifort project is also x64 or is it ia32 project?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 15:32:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686359#M175652</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2025-04-29T15:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Error with the IFX compiler when I call a Fortran subroutine from C#</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686360#M175653</link>
      <description>&lt;P&gt;Here is an interesting thread on compiling the C# for x64/ia32.&amp;nbsp; The BadFormatException occurs when there is a mismatch between the calling C# program and the DLL in x64 vs ia32&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 15:37:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686360#M175653</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2025-04-29T15:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Error with the IFX compiler when I call a Fortran subroutine from C#</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686400#M175657</link>
      <description>&lt;P&gt;I don't know much about C#, but I did build a DLL from your code.&amp;nbsp; Using a default DLL project configuration.&amp;nbsp; In the thread I mentioned,&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/5229768/c-sharp-compiling-for-32-64-bit-or-for-any-cpu" target="_blank"&gt;https://stackoverflow.com/questions/5229768/c-sharp-compiling-for-32-64-bit-or-for-any-cpu&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(i forgot to put this in the last reply).&lt;BR /&gt;from a web search I learned you can tell if a DLL is ia32 or x64 by bringing the binary DLL into Notepad or Notepad+ and looking for the string "PE. " followed by either a letter:&lt;/P&gt;
&lt;UL data-hveid="CC0QAQ" data-ved="2ahUKEwj_wILVy_2MAxUQIEQIHep5CzYQm_YKegQILRAB"&gt;
&lt;LI class="K3KsMc"&gt;
&lt;DIV class="zMgcWd dSKvsb" data-il=""&gt;
&lt;DIV data-crb-p=""&gt;
&lt;DIV class="xFTqob"&gt;
&lt;DIV class="Gur8Ad"&gt;&lt;SPAN data-huuid="10751189413177080870"&gt;&lt;STRONG&gt;Determining DLL Architecture:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="vM0jzc"&gt;&lt;SPAN data-huuid="10751189413177079819"&gt;You can determine if a DLL is 32-bit or 64-bit by opening it in a text editor (like Notepad++) and searching for the "PE" header.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN data-huuid="10751189413177078768"&gt;The character following "PE" indicates the architecture.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN data-huuid="10751189413177081813"&gt;For 32-bit DLLs, the character after "PE" will be "L", while for 64-bit DLLs, it will be "t".&lt;SPAN class="pjBG2e" data-cid="dc3dc021-8ab4-4f73-9e3f-ecb829ceb684"&gt;&lt;SPAN class="UV3uM"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="vM0jzc"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="vM0jzc"&gt;&lt;SPAN data-huuid="10751189413177081813"&gt;&lt;SPAN class="pjBG2e" data-cid="dc3dc021-8ab4-4f73-9e3f-ecb829ceb684"&gt;&lt;SPAN class="UV3uM"&gt;The default for ifx is "t" which as expected is a x64 DLL.&amp;nbsp; So I think your C# code must be looking for a 32bit DLL&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="vM0jzc"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 29 Apr 2025 17:29:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686400#M175657</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2025-04-29T17:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error with the IFX compiler when I call a Fortran subroutine from C#</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686654#M175666</link>
      <description>&lt;P&gt;Both are x64.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 10:10:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686654#M175666</guid>
      <dc:creator>dj1967</dc:creator>
      <dc:date>2025-04-30T10:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Error with the IFX compiler when I call a Fortran subroutine from C#</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686655#M175667</link>
      <description>&lt;P&gt;Hello Ron&lt;/P&gt;&lt;P&gt;I've opened the IFX DLL with Notepad and the header says:&lt;/P&gt;&lt;P&gt;MZx &amp;#1; &amp;#4; @ x &amp;#14;&amp;#31;º&amp;#14; ´ Í!¸&amp;#1;LÍ!This program cannot be run in DOS mode.$ PE d†&amp;#11; .ù&amp;#17;h ð&lt;/P&gt;&lt;P&gt;The IFORT DLL also says&lt;/P&gt;&lt;P&gt;PE d†&lt;/P&gt;&lt;P&gt;Is there anything wrong?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 10:27:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Error-with-the-IFX-compiler-when-I-call-a-Fortran-subroutine/m-p/1686655#M175667</guid>
      <dc:creator>dj1967</dc:creator>
      <dc:date>2025-04-30T10:27:16Z</dc:date>
    </item>
  </channel>
</rss>

