<?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 If you are more comfortable in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001664#M103822</link>
    <description>&lt;P&gt;If you are more comfortable working in Visual Studio, after you have built foo.a rename it as FOO.LIB and add that import library file to your project in the usual way.&lt;/P&gt;

&lt;P&gt;This newly built FOO.LIB is the companion *.lib that you wrote about: "...&lt;SPAN style="font-size: 12px; line-height: 12px;"&gt;&lt;EM&gt;since the actual DLL I want to use once I get past this example does not have a companion *.lib&lt;/EM&gt;".&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Oct 2015 22:52:07 GMT</pubDate>
    <dc:creator>mecej4</dc:creator>
    <dc:date>2015-10-02T22:52:07Z</dc:date>
    <item>
      <title>How to import a DLL into a Microsoft Visual Studio Fortran Project?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001658#M103816</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am having problems importing a DLL into my current Fortran project. The DLL file I am trying to import, fdlltest.dll, has the following functions defined when I do dumpbin /exports:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;C:\temp&amp;gt;dumpbin /exports fdlltest.dll
Microsoft (R) COFF/PE Dumper Version 12.00.40629.0
Copyright (C) Microsoft Corporation.&amp;nbsp; All rights reserved.


Dump of file fdlltest.dll

File Type: DLL

&amp;nbsp; Section contains the following exports for fdlltest.dll

&amp;nbsp;&amp;nbsp;&amp;nbsp; 00000000 characteristics
&amp;nbsp;&amp;nbsp;&amp;nbsp; 560ED478 time date stamp Fri Oct 02 14:01:12 2015
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 version
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 ordinal base
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3 number of functions
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3 number of names

&amp;nbsp;&amp;nbsp;&amp;nbsp; ordinal hint RVA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 00001000 add2i
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 00001010 add2r
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 00001040 simpson

&amp;nbsp; Summary

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .data
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .rdata
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .reloc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .rsrc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .text&lt;/PRE&gt;

&lt;P&gt;Next, I need to know step-by-step how to import the add2i, add2r, and simpson functions from this DLL located in C:\temp into my current Fortran project. I do not want examples with *.lib, since the actual DLL I want to use once I get past this example does not have a companion *.lib. This is my Fortran code which is supposed to generate an EXE that is linked to the DLL file:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program fdllrun
&amp;nbsp;implicit none
INTERFACE
&amp;nbsp;INTEGER FUNCTION add2i(a,b) 
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"add2i" :: add2i
!DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp;&amp;nbsp;INTEGER, intent(in), value:: a, b
&amp;nbsp;END FUNCTION add2i
&amp;nbsp;
&amp;nbsp;REAL FUNCTION add2r(a,b)
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"add2r" :: add2r
!DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp;&amp;nbsp;REAL, intent(in), value:: a, b
&amp;nbsp;END FUNCTION add2r

&amp;nbsp;REAL FUNCTION simpson(f, a, b, n) 
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"simpson" :: simpson
!DEC$ ATTRIBUTES REFERENCE::f, a, b, n
&amp;nbsp;&amp;nbsp;EXTERNAL f
&amp;nbsp;&amp;nbsp;real, intent(in), value ::&amp;nbsp; a, b
&amp;nbsp;&amp;nbsp;integer, intent(in), value :: n
&amp;nbsp;END FUNCTION simpson
END INTERFACE 

&amp;nbsp;! Variables
&amp;nbsp;INTEGER :: i1, i2, ians
&amp;nbsp;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;i1=1
&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;i2=2
&lt;/FONT&gt;&lt;/FONT&gt;
&amp;nbsp;! Body of fdllrun
&amp;nbsp;ians = add2i(i1, i2)
&amp;nbsp;print '(I3)', ians

end program fdllrun&lt;/PRE&gt;

&lt;P&gt;I tried to right click on my project and do Add -&amp;gt; Existing Item, then browse to the DLL file located in C:\temp, then Build All. It does not work. The errors I get when I try to compile are:&lt;/P&gt;

&lt;P&gt;Error&amp;nbsp;1&amp;nbsp; error LNK2019: unresolved external symbol __imp_add2i referenced in function _MAIN__&amp;nbsp;fdllrun.obj&amp;nbsp;&lt;BR /&gt;
	Error&amp;nbsp;2&amp;nbsp; fatal error LNK1120: 1 unresolved externals&amp;nbsp;Release\fdllrun.exe&amp;nbsp;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 19:20:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001658#M103816</guid>
      <dc:creator>Jesse_B_1</dc:creator>
      <dc:date>2015-10-02T19:20:55Z</dc:date>
    </item>
    <item>
      <title>There are two mechanisms for</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001659#M103817</link>
      <description>&lt;P&gt;There are two mechanisms for an exe to link to a DLL - load time linking (happens automatically when the executable is loaded) and run time linking (happens until the control of specific code in the executable).&lt;/P&gt;

&lt;P&gt;(I lie a bit - there is also a third mechanism - delay load linking - a hybrid of those two, but I am not familiar with it, so, like all things I am mostly ignorant of, I just pretend it doesn't exist.)&lt;/P&gt;

&lt;P&gt;Which of those two mechanisms do you want?&lt;/P&gt;

&lt;P&gt;To do run time linking you use the LoadLibrary and GetProcAddress Win32 API's (or some wrapper around them) to load the library (by name0 and get the relevant procedure address (by name or ordinal) - storing the procedure address in a procedure or integer pointer, and invoking it through that.&amp;nbsp; Fortran examples of the use of those API's should be relatively easy to discover.&lt;/P&gt;

&lt;P&gt;To do load time linking (which is what I guess you want to do, given the interface blocks), at the time you build your executable you tell the linker that particular procedures are in a particular DLL.&amp;nbsp; You do that by providing the linker with an import library... i.e. a lib file.&amp;nbsp; Without such a library, the linker has no idea where the implementation of that procedure lives, so you get the error message you see.&amp;nbsp; If you want to use this mechanism and don't have an import library, then you need to make or get one.&lt;/P&gt;

&lt;P&gt;You can make an import library by hand by writing a module definition file or by compiling and linking a pretend DLL - see &lt;A href="https://support.microsoft.com/en-us/kb/131313" target="_blank"&gt;https://support.microsoft.com/en-us/kb/131313&lt;/A&gt; for starters.&amp;nbsp; There are tools out there that will do this from the information in the DLL, given certain assumptions, for you - I think I've seen such a tool in the mingw distribution of gcc.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 21:37:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001659#M103817</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2015-10-02T21:37:05Z</dc:date>
    </item>
    <item>
      <title>The tool is called dlltool</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001660#M103818</link>
      <description>&lt;P&gt;The tool is called dlltool.exe and there is an example at &lt;A href="https://cygwin.com/cygwin-ug-net/dll.html"&gt;https://cygwin.com/cygwin-ug-net/dll.html&lt;/A&gt; .&lt;/P&gt;

&lt;P&gt;Fleshing out the current code for this example, we start with foo.f90&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;MODULE M
&amp;nbsp;&amp;nbsp; implicit none
&amp;nbsp;&amp;nbsp; CONTAINS
&amp;nbsp;INTEGER FUNCTION add2i(a,b) 
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS:"add2i" :: add2i
!DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp; INTEGER, intent(in), value:: a, b
&amp;nbsp; add2i = a+b
&amp;nbsp;END FUNCTION add2i
&amp;nbsp;
&amp;nbsp;REAL FUNCTION add2r(a,b)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS:"add2r" :: add2r
!DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp; REAL, intent(in), value:: a, b
&amp;nbsp; add2r = a+b
&amp;nbsp;END FUNCTION add2r

&amp;nbsp;REAL FUNCTION simpson(f, a, b, n) 
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS:"simpson" :: simpson
!DEC$ ATTRIBUTES REFERENCE::f, a, b, n
&amp;nbsp; EXTERNAL f
&amp;nbsp; real f
&amp;nbsp; real, intent(in), value ::&amp;nbsp; a, b
&amp;nbsp; integer, intent(in), value :: n
&amp;nbsp; real h
&amp;nbsp; integer i
&amp;nbsp; h = (b-a)/2
&amp;nbsp; simpson = (h/3)*(f(a)+4*sum([(f(a+i*h),i=1,n-1,2)])+ &amp;amp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 2*sum([(f(a+i*h),i=2,n-2,2)])+f(b))
&amp;nbsp;END FUNCTION simpson
END MODULE M
&lt;/PRE&gt;

&lt;P&gt;Now we compile it with ifort /nologo /dll foo.f90 . Then we delete the foo.lib, foo.exp, and foo.obj files, just so that there is nothing in our hands, nothing up our sleeves. Now we need a *.DEF file, in this case foo.def is&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;EXPORTS
add2i
add2r
simpson
&lt;/PRE&gt;

&lt;P&gt;Then we use dlltool.exe to make a *.a file&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;C:\&amp;gt;dlltool --def foo.def --dllname foo.dll --output-lib foo.a&lt;/PRE&gt;

&lt;P&gt;And now we are ready to link with that *.a file:&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;C:/ifort /nologo fdllrun.f90 foo.a&lt;/PRE&gt;

&lt;P&gt;Oh yeah, we also needed an fdllrunf90 file&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program fdllrun
&amp;nbsp;implicit none
INTERFACE
&amp;nbsp;INTEGER FUNCTION add2i(a,b)
&amp;nbsp; implicit none
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"add2i" :: add2i
!DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp; INTEGER, intent(in), value:: a, b
&amp;nbsp;END FUNCTION add2i
&amp;nbsp;
&amp;nbsp;REAL FUNCTION add2r(a,b)
&amp;nbsp; implicit none
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"add2r" :: add2r
!DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp; REAL, intent(in), value:: a, b
&amp;nbsp;END FUNCTION add2r

&amp;nbsp;REAL FUNCTION simpson(f, a, b, n) 
&amp;nbsp; implicit none
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"simpson" :: simpson
!DEC$ ATTRIBUTES REFERENCE::f, a, b, n
&amp;nbsp; EXTERNAL f
&amp;nbsp; real f
&amp;nbsp; real, intent(in), value ::&amp;nbsp; a, b
&amp;nbsp; integer, intent(in), value :: n
&amp;nbsp;END FUNCTION simpson
END INTERFACE 

&amp;nbsp;! Variables
&amp;nbsp;INTEGER :: i1, i2, ians
&amp;nbsp;i1=1
&amp;nbsp;i2=2

&amp;nbsp;! Body of fdllrun
&amp;nbsp;ians = add2i(i1, i2)
&amp;nbsp;print '(I3)', ians

end program fdllrun
&lt;/PRE&gt;

&lt;P&gt;The output is 3, which is hopefully what you expected.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 21:50:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001660#M103818</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-10-02T21:50:33Z</dc:date>
    </item>
    <item>
      <title>Thank you Repeat Offender,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001661#M103819</link>
      <description>&lt;P&gt;Thank you Repeat Offender, for your detailed response. I got all the way up to where I need to use the command line for&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;C:/ifort /nologo fdllrun.f90 foo.a&lt;/PRE&gt;

&lt;P&gt;However, my Developer Command Prompt for VS2013 says ifort is not a recognized command or program. Are command line solution builds done somewhere else?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 22:19:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001661#M103819</guid>
      <dc:creator>Jesse_B_1</dc:creator>
      <dc:date>2015-10-02T22:19:02Z</dc:date>
    </item>
    <item>
      <title>That's the Visual Studio only</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001662#M103820</link>
      <description>&lt;P&gt;That's the Visual Studio only command prompt (hence it has no idea about Fortran).&amp;nbsp; The command prompts for the Fortran compiler are accessible under the Intel Parallel Studio &amp;gt; Compilers and Libraries (or similar, depending on version) start menu items.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 22:41:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001662#M103820</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2015-10-02T22:41:23Z</dc:date>
    </item>
    <item>
      <title>Ok, I just gave it a try, I</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001663#M103821</link>
      <description>&lt;P&gt;Ok, I just gave it a try, I got:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;C:\..&amp;gt;ifort /nologo fdllrun.f90 foo.a
fdllrun.obj : error LNK2019: unresolved external symbol __imp_add2i referenced 
in function MAIN__
fdllrun.exe : fatal error LNK1120: 1 unresolved externals&lt;/PRE&gt;

&lt;P&gt;The solution did sound nice, but it did not work. I tried with both the 32 bit and 64 bit Intel Compiler command prompt. Any ideas what I may be doing wrong?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 22:48:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001663#M103821</guid>
      <dc:creator>Jesse_B_1</dc:creator>
      <dc:date>2015-10-02T22:48:55Z</dc:date>
    </item>
    <item>
      <title>If you are more comfortable</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001664#M103822</link>
      <description>&lt;P&gt;If you are more comfortable working in Visual Studio, after you have built foo.a rename it as FOO.LIB and add that import library file to your project in the usual way.&lt;/P&gt;

&lt;P&gt;This newly built FOO.LIB is the companion *.lib that you wrote about: "...&lt;SPAN style="font-size: 12px; line-height: 12px;"&gt;&lt;EM&gt;since the actual DLL I want to use once I get past this example does not have a companion *.lib&lt;/EM&gt;".&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 22:52:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001664#M103822</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2015-10-02T22:52:07Z</dc:date>
    </item>
    <item>
      <title>Ok, so after renaming foo.a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001665#M103823</link>
      <description>&lt;P&gt;Ok, so after renaming foo.a to foo.lib, where do I put it when I Add Existing Item? I tried both foo.lib alone, as well as it along with fdlltest.dll and placed them beneath the "fdllrun" project tree. Same errors, all to no avail.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 22:59:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001665#M103823</guid>
      <dc:creator>Jesse_B_1</dc:creator>
      <dc:date>2015-10-02T22:59:52Z</dc:date>
    </item>
    <item>
      <title>Well, it worked for me. I</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001666#M103824</link>
      <description>&lt;P&gt;Well, it worked for me. I used the latest ifort, along with the dlltool.exe that came with gfortran 5.2, both 64-bit. I tried 32-bit ifort and apparently 32-bit dlltool.exe and I got the same error that you did. Here is my CMD.EXE session, given foo.f90, foo.def, and fdllrun.f90 as in Quote #3&lt;/P&gt;

&lt;PRE class="brush:plain;"&gt;C:\New folder&amp;gt;dir
&amp;nbsp;Volume in drive C is Windows
&amp;nbsp;Volume Serial Number is 58F5-A85A

&amp;nbsp;Directory of C:\New folder

10/02/2015&amp;nbsp; 05:35 PM&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DIR&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .
10/02/2015&amp;nbsp; 05:35 PM&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DIR&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ..
10/02/2015&amp;nbsp; 03:39 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 854 fdllrun.f90
10/02/2015&amp;nbsp; 03:37 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 32 foo.def
10/02/2015&amp;nbsp; 03:32 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 821 foo.f90
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3 File(s)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1,707 bytes
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 Dir(s)&amp;nbsp; 48,220,049,408 bytes free

C:\New folder&amp;gt;ifort /nologo /dll foo.f90
&amp;nbsp;&amp;nbsp; Creating library foo.lib and object foo.exp

C:\New folder&amp;gt;del foo.lib foo.exp foo.obj

C:\New folder&amp;gt;dir
&amp;nbsp;Volume in drive C is Windows
&amp;nbsp;Volume Serial Number is 58F5-A85A

&amp;nbsp;Directory of C:\New folder

10/02/2015&amp;nbsp; 05:36 PM&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DIR&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .
10/02/2015&amp;nbsp; 05:36 PM&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DIR&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ..
10/02/2015&amp;nbsp; 03:39 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 854 fdllrun.f90
10/02/2015&amp;nbsp; 03:37 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 32 foo.def
10/02/2015&amp;nbsp; 05:35 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7,680 foo.dll
10/02/2015&amp;nbsp; 03:32 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 821 foo.f90
10/02/2015&amp;nbsp; 05:35 PM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1,500 m.mod
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5 File(s)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10,887 bytes
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 Dir(s)&amp;nbsp; 48,220,037,120 bytes free

C:\New folder&amp;gt;dlltool --def foo.def --dllname foo.dll --output-lib foo.a

C:\New folder&amp;gt;ifort /nologo fdllrun.f90 foo.a

C:\New folder&amp;gt;fdllrun
&amp;nbsp; 3
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 23:45:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001666#M103824</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-10-02T23:45:23Z</dc:date>
    </item>
    <item>
      <title>OK, I found out what went</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001667#M103825</link>
      <description>&lt;P&gt;OK, I found out what went wrong with the 32-bit build. In that case, dlltool.exe prepends underscores to the names but ifort, since you are using the ALIAS attribute, does not. It might be possible to fix this by using BIND(C) instead of !DEC$ ATTRIBUTES, or by adding the DECORATE attribute (I didn't check) but certainly putting underscores in there works. Here is the file that worked for the 32-bit build, fdllrun32.f90&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program fdllrun
&amp;nbsp;implicit none
INTERFACE
&amp;nbsp;INTEGER FUNCTION add2i(a,b)
&amp;nbsp; implicit none
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"_add2i" :: add2i
!DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp; INTEGER, intent(in), value:: a, b
&amp;nbsp;END FUNCTION add2i
&amp;nbsp;
&amp;nbsp;REAL FUNCTION add2r(a,b)
&amp;nbsp; implicit none
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"_add2r" :: add2r
!DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp; REAL, intent(in), value:: a, b
&amp;nbsp;END FUNCTION add2r

&amp;nbsp;REAL FUNCTION simpson(f, a, b, n) 
&amp;nbsp; implicit none
!DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"_simpson" :: simpson
!DEC$ ATTRIBUTES REFERENCE::f, a, b, n
&amp;nbsp; EXTERNAL f
&amp;nbsp; real f
&amp;nbsp; real, intent(in), value ::&amp;nbsp; a, b
&amp;nbsp; integer, intent(in), value :: n
&amp;nbsp;END FUNCTION simpson
END INTERFACE 

&amp;nbsp;! Variables
&amp;nbsp;INTEGER :: i1, i2, ians
&amp;nbsp;i1=1
&amp;nbsp;i2=2

&amp;nbsp;! Body of fdllrun
&amp;nbsp;ians = add2i(i1, i2)
&amp;nbsp;print '(I3)', ians

end program fdllrun
&lt;/PRE&gt;

&lt;P&gt;Now I could compile with ifort /nologo fdllrun32.f90 foo.a, and the resulting fdllrun32.exe produces the output 3, as before. I just checked and the DECORATE attribute works in your case, so your best option, rather than maintaining a separate function ALIAS for 32- and 64-bit versions, is to add the DECORATE attribute to each function name in each interface body in the calling program unit.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2015 00:10:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001667#M103825</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-10-03T00:10:07Z</dc:date>
    </item>
    <item>
      <title>I don't think you actually</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001668#M103826</link>
      <description>&lt;P&gt;I don't think you actually need that dlltool to do this - the windows system linker (moonlighting as lib.exe) can generate import libraries from def files (lib.exe /def:foo.def /out:foo.lib).&amp;nbsp; You will have the same extraneous underscore issue on x86 though.&amp;nbsp; The workaround for that is just to compile the dummy dll that you had in #3... delete the resulting dll and just use its lib file.&lt;/P&gt;

&lt;P&gt;For the OP - you do need to be consistent in your bitness between your DLL and your EXE.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2015 02:23:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001668#M103826</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2015-10-03T02:23:56Z</dc:date>
    </item>
    <item>
      <title>Thank you Repeat Offender,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001669#M103827</link>
      <description>&lt;P&gt;Thank you Repeat Offender, your clarifications were helpful! I did a little more reading on the DECORATE flag, and put this into my Visual Studio program making the DLL file:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;!DEC$ IF DEFINED(_WIN32) 
&amp;nbsp;!DEC$ ATTRIBUTES DECORATE, DLLEXPORT, ALIAS:"add2i" :: add2i 
!DEC$ ELSE 
&amp;nbsp;!DEC$ ATTRIBUTES DECORATE, DLLEXPORT, ALIAS:"add2i_" :: add2i 
!DEC$ END IF 
!DEC$ ATTRIBUTES REFERENCE :: x, y&lt;/PRE&gt;

&lt;P&gt;I then went to doing the same command line commands that you suggested earlier with dlltool to make *.a:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;C:\...&amp;gt;dlltool --def fdlltest.def --dllname fdlltest.dll --output-lib fdlltest.a&lt;/PRE&gt;

&lt;P&gt;Next, I did something fairly similar with DECORATE in the main Visual Studio program using the DLL file:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;!DEC$ ATTRIBUTES DECORATE, DLLIMPORT, ALIAS:"add2i" :: add2i
!DEC$ ATTRIBUTES REFERENCE::a, b&lt;/PRE&gt;

&lt;P&gt;I next tried to use mesej4's method for creating a *.lib file and added it to the main Visual Studio program (inside the fdllrun tree) and attempted to build within Visual Studio, but that did not work. mesej4, perhaps you could clarify how you set up Visual Studio and the loading of files that got it working for you within the GUI?&lt;/P&gt;

&lt;P&gt;So I went back to the command line method suggested earlier by Repeat Offender:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;C:\...&amp;gt;ifort /nologo fdllrun.f90 fdlltest.a&lt;/PRE&gt;

&lt;P&gt;It then built without any errors! Next, I ran it:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;C:\...&amp;gt;fdllrun.exe
3&lt;/PRE&gt;

&lt;P&gt;So it is now working with this example!&lt;/P&gt;

&lt;P&gt;Hopefully the last thing, but how do you choose a 32 bit compilation in Intel Fortran Visual Studio? When I go to Configuration Manager and try to change the Platform from Win32, my only option for New platform is "x64". I need to be able to select 32 bit as the actual DLL files I'm trying to use were compiled in 32 bit. I guess the only way to choose between one or the other is with Intel Compiler version you launch, IA-32 or Intel 64?&lt;/P&gt;

&lt;P&gt;Thanks again for the help.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2015 19:32:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001669#M103827</guid>
      <dc:creator>Jesse_B_1</dc:creator>
      <dc:date>2015-10-03T19:32:18Z</dc:date>
    </item>
    <item>
      <title>Win32 is the 32 bit</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001670#M103828</link>
      <description>&lt;P&gt;Win32 is the 32 bit configuration (also known as x86 or IA-32).&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2015 20:25:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001670#M103828</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2015-10-03T20:25:30Z</dc:date>
    </item>
    <item>
      <title>I got this to work in Visual</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001671#M103829</link>
      <description>&lt;P&gt;I got this to work in Visual Studio. First, in some neutral directory, from the 32-bit ifort command prompt, I compiled foo.f90 to a DLL with&lt;/P&gt;

&lt;P&gt;ifort /nologo /dll foo.f90&lt;/P&gt;

&lt;P&gt;and then with the command&lt;/P&gt;

&lt;P&gt;lib /def:foo.def /out:foo.lib&lt;/P&gt;

&lt;P&gt;made the foo.lib file. Note that I used the foo.f90 from Quote #3; the modifications in Quote #12 are wrong because, firstly, the reason for the DECORATE attribute is to avoid the conditional compilation with !DEC$ IF DEFINED(_WIN32), so you don't need them both. Secondly, you don't need DECORATE here unless the calling convention of the DLL is set to STDCALL. Third, the ALIAS of 'add2i_' is wrong anyway. Just use dumpbin /exports to see what the symbols from your target DLL look like and see if what this test DLL exports look similar. Can you disclose as much as one symbol exported by the target DLL as seen by dumpbin /exports?&lt;/P&gt;

&lt;P&gt;Ok, now start Visual Studio, start a new project, and under Intel(R) Visual Fortran, Console Application, select Empty Project, Name: fdllrun, check Create directory for solution, then OK. Now open a couple of Windows explorers &amp;lt;WINDOWS&amp;gt;+E &amp;lt;WINDOWS&amp;gt;+&amp;lt;LEFT&amp;gt; &amp;lt;WINDOWS&amp;gt;+E &amp;lt;WINDOWS&amp;gt;+&amp;lt;RIGHT&amp;gt; and navigate to where your original fdllrun.f90 file as you modified it with DECORATE is and copy it over to D:\blahblahblah\fdllrun\fdllrun . Then you should be able to add it as an existing source file.&lt;/P&gt;

&lt;P&gt;Then you have to go to Project -&amp;gt; fdllrun properties -&amp;gt; Linker -&amp;gt; general, and set the directory where that foo.lib that you made resides as an Additional Library Directory. Also under Linker -&amp;gt; Input, set foo.lib as an additional dependency. Then select OK.&lt;/P&gt;

&lt;P&gt;Then you can do build -&amp;gt; rebuild solution and it should build but not run because that DLL isn't on your path. To fix this, go back to your two copies of Windows Explorer and copy foo.lib from where it is to D:\blahblahblah\fdllrun\fdllrun, and also copy foo.dll to D:\blahblahblah\fdllrun\fdllrun\release (I assumed a release build here; maybe you need debug instead of release?) Then you can go back to Project -&amp;gt; fdllrun properties -&amp;gt; Linker -&amp;gt; general -&amp;gt; Additional Library Directories and change that directory to D:\blahblahblah\fdllrun\fdllrun\release (or debug as the case may be).&lt;/P&gt;

&lt;P&gt;Now you can do build -&amp;gt; rebuild all, and it should build, then debug -&amp;gt; start without debugging, and it should run to completion. If I can figure out how to do this in Visual Studio, anyone can do it.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2015 21:57:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001671#M103829</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-10-03T21:57:13Z</dc:date>
    </item>
    <item>
      <title>Oops, that last additional</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001672#M103830</link>
      <description>&lt;P&gt;Oops, that last additional library directory should have been D:\blahblahblah\fdllrun\fdllrun, the directory where you put foo.lib. You can't put foo.lib in the release or debug directory because is then gets trashed by Rebuild All.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2015 22:00:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001672#M103830</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-10-03T22:00:09Z</dc:date>
    </item>
    <item>
      <title>Thanks Repeat Offender, your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001673#M103831</link>
      <description>&lt;P&gt;Thanks Repeat Offender, your answers were helpful and enabled me to successfully compile and run&amp;nbsp;in the Visual Studio environment. Everything is now working in these tests.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 14:20:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001673#M103831</guid>
      <dc:creator>Jesse_B_1</dc:creator>
      <dc:date>2015-10-05T14:20:09Z</dc:date>
    </item>
    <item>
      <title>I should add one more thing.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001674#M103832</link>
      <description>&lt;P&gt;I should add one more thing. I had to tweak some things to get C++ DLL imports to work. But the same concepts with making lib and def files, then moving the lib and dll file into the same directory as the code and changing the linker settings still applied.&lt;/P&gt;

&lt;P&gt;Here was the dumpbin output of my C++ DLL (I made sure to use&amp;nbsp;extern "C" within the C++ code):&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;c:\...&amp;gt;dumpbin /exports cdlltest.dll
Microsoft (R) COFF/PE Dumper Version 12.00.40629.0
Copyright (C) Microsoft Corporation.&amp;nbsp; All rights reserved.


Dump of file cdlltest.dll

File Type: DLL

&amp;nbsp; Section contains the following exports for cdlltest.dll

&amp;nbsp;&amp;nbsp;&amp;nbsp; 00000000 characteristics
&amp;nbsp;&amp;nbsp;&amp;nbsp; 560DA48A time date stamp Thu Oct 01 16:24:26 2015
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 version
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 ordinal base
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5 number of functions
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5 number of names

&amp;nbsp;&amp;nbsp;&amp;nbsp; ordinal hint RVA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 000010A0 add
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 000010D0 divide
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 00001140 modulus
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp; 3 000010C0 multiply
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp; 4 000010B0 subtract

&amp;nbsp; Summary

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .data
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .rdata
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .reloc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .rsrc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1000 .text&lt;/PRE&gt;

&lt;P&gt;Here is how I had to modify the Fortran code:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program cdllrun
&amp;nbsp;USE, intrinsic :: ISO_C_BINDING, only: C_INT, C_DOUBLE
&amp;nbsp;implicit none
INTERFACE
&amp;nbsp;SUBROUTINE modulus(a, b, ans) BIND(C, name='modulus')
&amp;nbsp;&amp;nbsp;import
&amp;nbsp;&amp;nbsp;implicit none
! !DEC$ ATTRIBUTES DECORATE, DLLIMPORT, ALIAS:"modulus" :: modulus
! !DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp;&amp;nbsp;INTEGER(KIND=C_INT), intent(in), value:: a, b
&amp;nbsp;&amp;nbsp;INTEGER(KIND=C_INT), intent(out) :: ans
&amp;nbsp;END SUBROUTINE modulus

&amp;nbsp;REAL(KIND=C_DOUBLE) FUNCTION add(a, b) BIND(C, name='add')
&amp;nbsp;&amp;nbsp;import
&amp;nbsp;&amp;nbsp;implicit none
! !DEC$ ATTRIBUTES DECORATE, DLLIMPORT, ALIAS:"add" :: add
! !DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp;&amp;nbsp;REAL(KIND=C_DOUBLE), intent(in), value:: a, b
&amp;nbsp;END FUNCTION add
&amp;nbsp;
&amp;nbsp;REAL(KIND=C_DOUBLE) FUNCTION subtract(a, b) BIND(C, name='subtract')
&amp;nbsp;&amp;nbsp;import
&amp;nbsp;&amp;nbsp;implicit none
! !DEC$ ATTRIBUTES DECORATE, DLLIMPORT, ALIAS:"subtract" :: subtract
! !DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp;&amp;nbsp;REAL(KIND=C_DOUBLE), intent(in), value:: a, b
&amp;nbsp;END FUNCTION subtract

&amp;nbsp;REAL(KIND=C_DOUBLE) FUNCTION multiply(a, b) BIND(C, name='multiply')
&amp;nbsp;&amp;nbsp;import
&amp;nbsp;&amp;nbsp;implicit none
! !DEC$ ATTRIBUTES DECORATE, DLLIMPORT, ALIAS:"multiply" :: multiply
! !DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp;&amp;nbsp;REAL(KIND=C_DOUBLE), intent(in), value:: a, b
&amp;nbsp;END FUNCTION multiply

&amp;nbsp;REAL(KIND=C_DOUBLE) FUNCTION divide(a, b) BIND(C, name='divide')
&amp;nbsp;&amp;nbsp;import
&amp;nbsp;&amp;nbsp;implicit none
! !DEC$ ATTRIBUTES DECORATE, DLLIMPORT, ALIAS:"divide" :: divide
! !DEC$ ATTRIBUTES REFERENCE::a, b
&amp;nbsp;&amp;nbsp;REAL(KIND=C_DOUBLE), intent(in), value:: a, b
&amp;nbsp;END FUNCTION divide
&amp;nbsp;
END INTERFACE 

&amp;nbsp;! Variables
&amp;nbsp;INTEGER(KIND=C_INT) :: i1, i2, ians
&amp;nbsp;i1=65
&amp;nbsp;i2=8
&amp;nbsp;
&amp;nbsp;! Body of cdllrun
&amp;nbsp;CALL modulus(i1, i2, ians)
&amp;nbsp;print '(I3)', ians

end program cdllrun
&lt;/PRE&gt;

&lt;P&gt;The answer was 1. I followed the thread here to help come up with the right code:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/278937" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/278937&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 15:41:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001674#M103832</guid>
      <dc:creator>Jesse_B_1</dc:creator>
      <dc:date>2015-10-05T15:41:27Z</dc:date>
    </item>
    <item>
      <title>Good to hear that things are</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001675#M103833</link>
      <description>&lt;P&gt;Good to hear that things are going well, and also that you changed over to BIND(C) instead of !DEC$ ATTRIBUTES to handle interfacing issues. The only reason I couched my replies in terms of !DEC$ ATTRIBUTES was on the off-chance that the DLL you were trying to interface to was itself written in Intel Fortran, in which case it might prove awkward to match up assumed-shape arguments, for example,&amp;nbsp;with BIND(C). In just about all other cases (VARYING being one exception) BIND(C) is much more straightforward and transportable.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2015 17:00:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-to-import-a-DLL-into-a-Microsoft-Visual-Studio-Fortran/m-p/1001675#M103833</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-10-05T17:00:30Z</dc:date>
    </item>
  </channel>
</rss>

