<?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 So it's like DllMain returns in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131350#M134384</link>
    <description>&lt;P&gt;So it's like DllMain returns false.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Feb 2020 12:38:09 GMT</pubDate>
    <dc:creator>GVautier</dc:creator>
    <dc:date>2020-02-26T12:38:09Z</dc:date>
    <item>
      <title>loadlibrary relative path problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131342#M134376</link>
      <description>&lt;P&gt;I have a problem when calling loadlibrary with relative paths:&lt;/P&gt;&lt;P&gt;- compiled with default static libs, the loadlibrary does not work with relative paths after a call to DAXPY&lt;/P&gt;&lt;P&gt;- compiled with libs:dll, relative paths does not work at all&lt;/P&gt;&lt;P&gt;Details:&lt;/P&gt;&lt;P&gt;- intel fortran 2020 (Intel® Parallel Studio XE 2020 Composer Edition for Fortran Windows* Integration for Microsoft Visual Studio* 2019, Version 19.1.0055.16) - Visual studio 2019 (Microsoft Visual Studio Professional 2019, Version 16.4.5)&lt;/P&gt;&lt;P&gt;- compile options: /Od /warn:interfaces /module:"Debug\\" /object:"Debug\\" /Fd"Debug\vc160.pdb" /traceback /check:bounds /check:stack /libs:static /threads /Qmkl:sequential /c - linker options: /OUT:"Debug\Console13.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST:NO /SUBSYSTEM:CONSOLE /IMPLIB:"C:\Users\mmpe\source\repos\Console13\Console13\Debug\Console13.lib"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Minimal example:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;program Test
  use dfwin, only: loadlibrary
  implicit none

  print *, "rel path", loadlibrary('./tmp/tmp.dll')/=0
  CALL DAXPY(3,[1d0,2d0,3d0],[2d0,2d0,2d0], 1, [3d0,3d0,3d0],1)
  print *, "abs path after daxpy", &amp;amp;nbsp;loadlibrary('C:/tmp/tmp.dll')/=0
  print *, "rel path after daxpy", loadlibrary('./tmp/tmp.dll')/=0
  end program&lt;/PRE&gt;

&lt;P&gt;Output (multithreaded):&lt;/P&gt;
&lt;P&gt;rel path T&lt;/P&gt;
&lt;P&gt;abs path after daxpy T&lt;/P&gt;
&lt;P&gt;rel path after daxpy F&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output (multithreaded dll):&lt;/P&gt;
&lt;P&gt;rel path F&lt;/P&gt;
&lt;P&gt;abs path after daxpy T&lt;/P&gt;
&lt;P&gt;rel path after daxpy F&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 12:51:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131342#M134376</guid>
      <dc:creator>Pedersen__M</dc:creator>
      <dc:date>2020-02-25T12:51:41Z</dc:date>
    </item>
    <item>
      <title>I suspect that your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131343#M134377</link>
      <description>&lt;P&gt;I suspect that your execuitable's (at time of launch) current directory is not what you expect. Note, depending on how you launch the application, the current directory is not necessarily the same directory as that of the .exe.&lt;/P&gt;&lt;P&gt;I haven't tested this, you can experiment:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;INQUIRE (DIRECTORY=dir, EXIST=ex [, DIRSPEC=dirspec] [, ERR=label] [, ID=id-var] [, IOMSG=msg-var] [, SIZE=sz] [, IOSTAT=i-var])&lt;/PRE&gt;

&lt;P&gt;where you would use "." as the directory, you add a character variable dirspec of sufficient size (say 500 characters), and you supply the DIRSPEC= argument as well as additional arguments as you see fit.&lt;/P&gt;
&lt;P&gt;Place the INQUIRE and PRINT *,dirspec before and after the call to DAXPY&lt;/P&gt;
&lt;P&gt;Jim Dempsey&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 13:49:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131343#M134377</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2020-02-25T13:49:44Z</dc:date>
    </item>
    <item>
      <title>What do you want? I often get</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131344#M134378</link>
      <description>&lt;P&gt;What do you want? I often get the path of the exe from the command line args function&amp;nbsp;and then use that as part of an absolute path. Windows has a complicated hierarchy of saving folder locations that varies dependant on windows version and the current phase of the moon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 15:04:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131344#M134378</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2020-02-25T15:04:00Z</dc:date>
    </item>
    <item>
      <title>The program shown is</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131345#M134379</link>
      <description>&lt;P&gt;The program shown is incorrect. The path string supplied to LoadLibrary should be NUL-terminated and should use backslashes. If it works at all it is accidental.&lt;/P&gt;&lt;P&gt;When a program is run from Visual Studio, the current directory is the one with the project folder, not the executable.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 16:39:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131345#M134379</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2020-02-25T16:39:37Z</dc:date>
    </item>
    <item>
      <title>Quote:andrew_4619 wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131346#M134380</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;andrew_4619 wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I often get the path of the exe from the command line args function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Under certain circumstances, that doesn't work. Use GetModuleFileName instead and GetLongPathName next if the executable has been launched by its short name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 21:27:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131346#M134380</guid>
      <dc:creator>GVautier</dc:creator>
      <dc:date>2020-02-25T21:27:12Z</dc:date>
    </item>
    <item>
      <title>Thank you for your fast</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131347#M134381</link>
      <description>&lt;P&gt;Thank you for your fast replies&lt;/P&gt;&lt;P&gt;I have modified the example program according to your suggestions, see below.&lt;BR /&gt;I set the working dir from visual studio: project settings - debugging - current working directory: c:\&lt;/P&gt;&lt;P&gt;Findings:&lt;/P&gt;&lt;P&gt;- The current working directory is c:\ both before and after DAXPY as expected&lt;/P&gt;&lt;P&gt;- Intel fortran 2019 update 5: relative path&amp;nbsp;works&lt;/P&gt;&lt;P&gt;- Intel fortran 2020,&amp;nbsp;Multithreaded: relative path works only before DAXPY&lt;/P&gt;&lt;P&gt;- Intel fortran 2020,&amp;nbsp;Multithreaded DLL: relative path does not work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example program&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;&amp;nbsp; &amp;nbsp; program Test
&amp;nbsp; &amp;nbsp; use dfwin, only: loadlibrary
&amp;nbsp; &amp;nbsp; implicit none
&amp;nbsp; &amp;nbsp; character*255 dirspec
&amp;nbsp; &amp;nbsp; LOGICAL ex
&amp;nbsp; &amp;nbsp; INQUIRE (DIRECTORY='.', EXIST=ex, DIRSPEC=dirspec)
&amp;nbsp; &amp;nbsp; print *, "CWD: ", trim(dirspec)
&amp;nbsp; &amp;nbsp; print *, "rel path", loadlibrary('.\tmp\tmp.dll'//char(0))/=0
&amp;nbsp; &amp;nbsp; CALL DAXPY(3,[1d0,2d0,3d0],[2d0,2d0,2d0], 1, [3d0,3d0,3d0],1)
&amp;nbsp; &amp;nbsp; INQUIRE (DIRECTORY='.', EXIST=ex, DIRSPEC=dirspec)
&amp;nbsp; &amp;nbsp; print *, "CWD: ", trim(dirspec)
&amp;nbsp; &amp;nbsp; print *, "abs path after daxpy", &amp;nbsp;loadlibrary('C:\tmp\tmp.dll'//char(0))/=0
&amp;nbsp; &amp;nbsp; print *, "rel path after daxpy", loadlibrary('.\tmp\tmp.dll'//char(0))/=0
&amp;nbsp; &amp;nbsp; end program&lt;/PRE&gt;

&lt;P&gt;Intel fortran 2019 update 5, Version 19.0.0052.16 (both "multithreaded" and "multithreaded dll")&lt;BR /&gt;&amp;nbsp;CWD: C:\&lt;BR /&gt;&amp;nbsp;rel path T&lt;BR /&gt;&amp;nbsp;CWD: C:\&lt;BR /&gt;&amp;nbsp;abs path after daxpy T&lt;BR /&gt;&amp;nbsp;rel path after daxpy T&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Intel fortran 2020, Version 19.1.0055.16&lt;BR /&gt;Multithreaded&lt;BR /&gt;&amp;nbsp;CWD: C:\&lt;BR /&gt;&amp;nbsp;rel path T&lt;BR /&gt;&amp;nbsp;CWD: C:\&lt;BR /&gt;&amp;nbsp;abs path after daxpy T&lt;BR /&gt;&amp;nbsp;rel path after daxpy F&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Multithreaded Dll&lt;BR /&gt;&amp;nbsp;CWD: C:\&lt;BR /&gt;&amp;nbsp;rel path F&lt;BR /&gt;&amp;nbsp;CWD: C:\&lt;BR /&gt;&amp;nbsp;abs path after daxpy T&lt;BR /&gt;&amp;nbsp;rel path after daxpy F&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 07:57:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131347#M134381</guid>
      <dc:creator>Pedersen__M</dc:creator>
      <dc:date>2020-02-26T07:57:02Z</dc:date>
    </item>
    <item>
      <title>Call getlasterror after</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131348#M134382</link>
      <description>&lt;P&gt;Call getlasterror after loadlibrary fails. The error code may help.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 08:48:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131348#M134382</guid>
      <dc:creator>GVautier</dc:creator>
      <dc:date>2020-02-26T08:48:00Z</dc:date>
    </item>
    <item>
      <title>getlasterror returns 0</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131349#M134383</link>
      <description>&lt;P&gt;getlasterror returns 0&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 11:35:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131349#M134383</guid>
      <dc:creator>Pedersen__M</dc:creator>
      <dc:date>2020-02-26T11:35:33Z</dc:date>
    </item>
    <item>
      <title>So it's like DllMain returns</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131350#M134384</link>
      <description>&lt;P&gt;So it's like DllMain returns false.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 12:38:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131350#M134384</guid>
      <dc:creator>GVautier</dc:creator>
      <dc:date>2020-02-26T12:38:09Z</dc:date>
    </item>
    <item>
      <title>The write statement may reset</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131351#M134385</link>
      <description>&lt;P&gt;The write statement may reset the last error.&lt;/P&gt;&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;iret=loadlibrary(...)&lt;/P&gt;&lt;P&gt;ierr=getlasterror()&lt;/P&gt;&lt;P&gt;write(...)... ret/=0,ierr&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 13:20:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131351#M134385</guid>
      <dc:creator>GVautier</dc:creator>
      <dc:date>2020-02-26T13:20:25Z</dc:date>
    </item>
    <item>
      <title>You may call:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131352#M134386</link>
      <description>&lt;P&gt;You may call:&lt;/P&gt;&lt;P&gt;DWORD GetCurrentDirectory(&amp;nbsp;DWORD &amp;nbsp;nBufferLength,&amp;nbsp; LPTSTR lpBuffer)&lt;BR /&gt;before and after DAXPY and LoadLibrary to see what is changed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 14:07:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131352#M134386</guid>
      <dc:creator>LRaim</dc:creator>
      <dc:date>2020-02-26T14:07:29Z</dc:date>
    </item>
    <item>
      <title>I cannot say this for certain</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131353#M134387</link>
      <description>&lt;P&gt;I cannot say this for certain, the return of False&amp;nbsp;may be a case of "The specified library was not loaded... because it is already present".&lt;/P&gt;&lt;P&gt;IOW&lt;/P&gt;&lt;P&gt;Implementation 1: The specified library is loaded&lt;BR /&gt;Implementation 2: The load operation succeeded&lt;/P&gt;&lt;P&gt;These two&amp;nbsp;results are only equivalent when the specified library was not present in memory when the function call was made.&lt;/P&gt;&lt;P&gt;Suggestions:&lt;/P&gt;&lt;P&gt;1) Save the return handle from LoadLibrary into a SAVE (or module) integer(handle) variable or array of said variables in the event you have multiple libraries you desire to control. Initialize these with 0 to indicate not loaded.&lt;BR /&gt;2) Test saved handle prior to LoadLibrary and use that in place of performing redundant load library&lt;BR /&gt;3) After step 2), use GetProcAddress to obtain (first time) or confirm (second and later) entry points to desired procedures.&lt;BR /&gt;4) When finished with a given library, issue FreeLibrary (and remember to zero out saved handle, and all saved procedure entry points for that library)&lt;/P&gt;&lt;P&gt;See: &lt;A href="https://docs.microsoft.com/en-us/windows/win32/dlls/using-run-time-dynamic-linking" target="_blank"&gt;https://docs.microsoft.com/en-us/windows/win32/dlls/using-run-time-dynamic-linking&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 16:09:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131353#M134387</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2020-02-26T16:09:00Z</dc:date>
    </item>
    <item>
      <title>@Luigi R: I was not able to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131354#M134388</link>
      <description>&lt;P&gt;@Luigi R: I was not able to call&amp;nbsp;GetCurrentDirectory (In which module is it defined?). I have tried with both inquire as Jim suggest and with getcwd. In both cases the path is as expected and unchanged after DAXPY&lt;/P&gt;&lt;P&gt;@jimdempseyatthecove (Blackbelt): It is not related to opening the dll twice. It is the same if I invoke loadlibrary once after DAXPY&lt;/P&gt;&lt;P&gt;It seems to be related to visual studio in combination with intel fortran 2020 as it works when I compile&amp;nbsp;from commandline with:&lt;/P&gt;&lt;P&gt;ifort test_rel_path.f90 /Qmkl:sequential /libs:static&amp;nbsp;/fpp /list&lt;/P&gt;&lt;P&gt;I have attached the lst-files generated via cmd&amp;nbsp;and VS.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 11:58:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/loadlibrary-relative-path-problem/m-p/1131354#M134388</guid>
      <dc:creator>Pedersen__M</dc:creator>
      <dc:date>2020-02-27T11:58:00Z</dc:date>
    </item>
  </channel>
</rss>

