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

Access to Kernel32 function SetDllDirectory

kingjsegmail_com
Beginner
715 Views

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 Solution
Arjen_Markus
Honored Contributor I
715 Views

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

View solution in original post

0 Kudos
5 Replies
Steven_L_Intel1
Employee
715 Views

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.

0 Kudos
Arjen_Markus
Honored Contributor I
716 Views

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

0 Kudos
kingjsegmail_com
Beginner
715 Views

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.

0 Kudos
Arjen_Markus
Honored Contributor I
715 Views

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

0 Kudos
Steven_L_Intel1
Employee
715 Views
It will be in winbase.h in the SDK include files. I found it there in the V6.0A (VS2008) SDK.
0 Kudos
Reply