Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29435 Diskussionen

Access to Kernel32 function SetDllDirectory

kingjsegmail_com
Einsteiger
1.897Aufrufe

Hello,

I have a FORTRAN program that needs to load DLL's on the fly (the name of the DLL isn't even know until an input file is read). You have been kind enough to include an interface for the LoadLibrary function in the Kernel32.f90 file that ships with Visual Fortan. However, this file does not have an interface for the C function SetDllDirectory, at least not in version 10.1.21.

[FYI:SetDllDirectory allows you to register a directory as part of the DLL search algorithm [link]. This is particularly important if you want to set a DLL search path without having to modify the %PATH% variable]

The C declaration is:

BOOL WINAPI SetDllDirectory(
  __in_opt  LPCTSTR lpPathName
);

Below is my attempt at a FORTRAN interface for SetDllDirectory. I modified the LoadLibrary Interface as I did not understand all of the !DEC calls. Some lines I had to comment out!

INTERFACE
FUNCTION SetDllDirectory(lpPathName)
import
logical(KIND=1) :: SetDllDirectory ! HMODULE
! !DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'SetDllDircetoryA' :: SetDllDircetory
!DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpPathName
character*(*) lpPathName ! LPCSTR lpPathName
END FUNCTION
END INTERFACE

It seemed to compile fine, but i get a linker error:

error LNK2001: unresolved external symbol _SETDLLDIRECTORY@8

I know thatkernel32.lib is being liked fine b/c the LoadLibrary function links fine. Can anyone see what I am doing wrong here? My FORTRAN isn't strong to begin with and when it comes to FORTRAN calling C I am very lost...

Any suggestions? Or better yet, a version of IVF that has the interface already in place?

Thanks!

0 Kudos
1 Lösung
Arjen_Markus
Geehrter Beitragender II
1.897Aufrufe

Note there is two typos in the commented!DEC$ line - SetDllDircetory should be SetDllDirectory (unless of course that is truly the name of the function).

Regards,

Arjen

Lösung in ursprünglichem Beitrag anzeigen

5 Antworten
Steven_L_Intel1
Mitarbeiter
1.897Aufrufe

You should have left the !DEC$ ATTRIBUTES line in there. It looks correct to me.

I don't think we've added that call - I'll check tomorrow. We have a lot of catching up to do in this regard.

Arjen_Markus
Geehrter Beitragender II
1.898Aufrufe

Note there is two typos in the commented!DEC$ line - SetDllDircetory should be SetDllDirectory (unless of course that is truly the name of the function).

Regards,

Arjen

kingjsegmail_com
Einsteiger
1.897Aufrufe

you are correct sir! sorry, after staring at it for so long, i missed the obvious spelling error. Made the correction and everything seems to link up fine!

INTERFACE
FUNCTION SetDllDirectory(lpPathName)
import
logical(KIND=1) :: SetDllDirectory ! HMODULE
!DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'SetDllDirectoryA' :: SetDllDirectory
!DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpPathName
character*(*) lpPathName ! LPCSTR lpPathName
END FUNCTION
END INTERFACE

Thank you both for your input and hopefully this will make it into IVF in a future release.

Arjen_Markus
Geehrter Beitragender II
1.897Aufrufe

Oddly enough I have not been able to find this function in the C header files for the MSVC compiler (I tried several versions).

Regards,

Arjen

Steven_L_Intel1
Mitarbeiter
1.897Aufrufe
It will be in winbase.h in the SDK include files. I found it there in the V6.0A (VS2008) SDK.
Antworten