On Tuesday, April 17, 2018 at 10:32:42 AM UTC-4, Arjen Markus wrote:
> ..
> we have run into a very odd and unwelcome problem with a program that runs fine on Windows 7 but fails on Windows 10. ..
>
> Does anyone have a suggestion as to what could be going wrong? ..
Well, age-old advice applies - of creating a *minimal working example* to diagnose the problem and if that fails, posting the complete code here.
A 2-minute effort I tried with a trivially simple example below works on both Windows 7 and 10:
--- code snippet ---
module m
use, intrinsic :: iso_c_binding, only : c_char, c_int, c_intptr_t, c_funptr
implicit none
!.. Public by default
public
!.. Mnemonics for types in Windows API functions
integer(c_int), parameter :: HMODULE = c_intptr_t !.. A handle to a module; base address in memory
integer(HMODULE), parameter :: NULL_HANDLE = int( 0, kind=kind(NULL_HANDLE) )
interface
function LoadLibrary(lpLibName) bind(C, name='LoadLibraryA') result(RetVal)
!
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx
! HMODULE WINAPI LoadLibrary(_In_ LPCTSTR lpFileName );
import :: c_char, HMODULE
!.. Argument list
character(kind=c_char, len=1) :: lpLibName(*)
!.. Function result
integer(HMODULE) :: RetVal
end function LoadLibrary
function GetProcAddress(lpLibHandle, lpProcName) bind(C, name='GetProcAddress') result(RetVal)
!
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683212(v=vs.85).aspx
! FARPROC WINAPI GetProcAddress( _In_ HMODULE hModule,
! _In_ LPCSTR lpProcName );
import :: HMODULE, c_char, c_funptr
!.. Argument list
integer(HMODULE), value :: lpLibHandle
character(kind=c_char) :: lpProcName(*)
!.. Function result
type(c_funptr) :: RetVal
end function GetProcAddress
end interface
end module m
program p
use, intrinsic :: iso_c_binding, only : c_char, c_funptr
use m, only : HMODULE, LoadLibrary, GetProcAddress, NULL_HANDLE
implicit none
! local variables
integer(HMODULE) :: hInstLib
type(c_funptr) :: pProc
hInstLib = LoadLibrary( c_char_"kernel32.dll" )
if ( NULL_HANDLE /= hInstLib ) then
pProc = GetProcAddress( hInstLib, c_char_"AddDllDirectory" )
print *, "ProcAddress of AddDllDirectory in loaded kernel32.dll: ", transfer( pProc, mold=hInstLib )
else
print *, "LoadLibrary failed."
end if
stop
end program p
--- end snippet ---
Here's the output on a Windows 10 machine running 64-bit OS with the program above built using Intel Fortran compiler and Microsoft C/C++ linker:
--- begin console output ---
C:\temp>p.exe
ProcAddress of AddDllDirectory in loaded kernel32.dll: 140732179481408
C:\temp>
--- end console output ---