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

Mixed Language DLL

rih3306
Beginner
279 Views
Hello Fortran Programmers,
I'm using CVF V6.6b, windows 2000 and trying to use a C++ DLL.
The linker can't find the function.
Depending on the version of the test program, the warning will be either
error LNK2001: unresolved external symbol _AppStatus
or
error LNK2001: unresolved external symbol _APPSTATUS@8
I've written an interface (see below) but am not sure if everything is OK.
In the interface block, how do you define the returned value of a function?
Where is the best place to locate the DLL?
Are there any special project settings?
All comments welcome.
Thanks,
Rob

!==================================================
program test_OneWay
use kernel32
implicit none
! project/settings/fortran/libraries ==> use-run-time-lirary/single-threaded-DLL
interface
logical function AppStatus(password)
!DEC$ ATTRIBUTES DLLIMPORT :: AppStatus
!DEC$ ATTRIBUTES C, ALIAS: '_AppStatus' :: AppStatus
character*(*) :: password
!DEC$ ATTRIBUTES REFERENCE :: password
end function AppStatus
end interface
character*128 password
integer i1way
pointer (p1way, i1way)
integer rtn_AppStatus
pointer (q1way, rtn_AppStatus)
logical status, stat2
! Locate the dll and load it into memory
p1way = loadlibrary("OneWay.dll"C)
if (p1way == 0) then
type *, "Error occurred opening OneWay.dll"
goto 1000
endif
! Set up a pointer to the routine of interest
q1way = getprocaddress(p1way, "AppStatus"C)
if (q1way == 0) then
type *, "Error occurred finding AppStatus in OneWay.dll"
goto 1000
endif
password = repeat(' ', len(password))
password = 'password'C
status = .false.
status = AppStatus(password)
write(*,*) status, password(1:8)
status = .false.
status = freelibrary(p1way)
if( .not. status) then
write(*,*) "freelibrary OneWay.dll status was: ", status
endif
1000 continue
end program test_OneWay
0 Kudos
1 Reply
anthonyrichards
New Contributor III
279 Views
If I recall correctly, you need to discover the name that C++ has given your function. It 'mangles, names by adding random alphanumerics. You can find out the name by using DUMPBIN on the DLL. This is the name you must reference it by in your FORTRAN calling program.
0 Kudos
Reply