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

calling C++ dll in Fotran

vincent22
Beginner
891 Views
Hello to all programmer guru,
I have a C++ dll and I want to call it in Visual Fortran, I have read an earlier thread about how to do.
But when the link it, i got the following error message:
error LNK2001: unresolved external symbol _GetSoftwareId
Debug/LoadExp1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
I have debugging the program and the getprocaddress command seems to be work.
The compiling ins ok also without any error.
My program is as follow:
program test
! Sample Fortran program that finds a dll library and calls
! a routine in it.
use kernel32
! Declare an interface block to the routine to be called.
interface
character Function GetSoftwareId()
!DEC$ ATTRIBUTES C, ALIAS:'_GetSoftwareId' :: GetSoftwareId
end Function GetSoftwareId
end interface


integer p
pointer (q,rtn_Jpn05)
logical status
character y

! First, locate the dll and load it into memory
p = loadlibrary("Jpn05.dll"C)
if (p == 0) then
type *, "Error occurred opening Jpn05.dll"
type *, "Program aborting"
goto 1000
endif
! Set up a pointer to the routine of interest
q = getprocaddress(p, "GetSoftwareId"C)
if (q == 0) then
type *, "Error occurred finding GetOutputNames in jpn05"
type *, "Program aborting"
goto 1000
endif
! the routine can be called
y = GetSoftwareId()
!
status = freelibrary(p)
type *, "freelibrary status was: ", status
1000continue
end program
Does some one know where the problems are?
Thanks in advanced!
/vincent

Message Edited by vincent22 on 03-07-200612:44 AM

Message Edited by vincent22 on 03-07-200612:45 AM

Message Edited by vincent22 on 03-07-2006 12:46 AM

Message Edited by vincent22 on 03-07-2006 12:48 AM

Message Edited by vincent22 on 03-07-2006 12:50 AM

Message Edited by vincent22 on 03-07-2006 12:53 AM

Message Edited by vincent22 on 03-07-2006 12:55 AM

Message Edited by vincent22 on 03-07-2006 01:05 AM

0 Kudos
4 Replies
anthonyrichards
New Contributor III
891 Views
The usual reply to this sort of problem is to try using the DUMPBIN utility on the .DLL to list the names exported from the DLL, so that you can see the exact decorated name that you need to call. If it differs from what you expect, then you need to create an alias to match it.
0 Kudos
vincent22
Beginner
891 Views
hello,
I had used the Dependency Walker and check the Functions in the DLL for spelling etc. and it seems to be ok.
Besr regards
Vincent
0 Kudos
Les_Neilson
Valued Contributor II
891 Views
Take a look at the Intel Fortranhelp - "Handling Character Strings" see the section on "Returning Character Data Types".
In the code you have shown you have declared "y" as character (ie *one* character in length)
Les
0 Kudos
vincent22
Beginner
891 Views
Hello,
Thanks to all reply.
Now I am find out that the output of the Function I am calling in the DLL is a pointer to a character array (I didn't make the dll).

char* GetSoftwareId();
Description: Returns the software ID for this software.

In what way should I declare it in the interface and the variable y.

Thanks to you all.

Vincent

0 Kudos
Reply