Dear all,
I wrote a programin Fortran to dynamically link a dll written in C++. I am using VS2008 with Intel Visual Fortran Compiler 10.1.019. It compiles / links with no errors. However I get a run-timeerror 'forrtl: severe (157) Program Exception - Access violation' .
The same code compiles/links/and runs with no errors in Compaq Visual Fortran Professional Edition 6.1.0.
Intel VFC debbuger points out that the error is in line 80:
Write (*,100) "ModelSetModelCpIgStandard returns: ", resModelSetComponentName
If instead of that, I write:
Write (*,*)resModelSetComponentName
... the program runs with no errors. Wierd, huh? I have no clue what's going on.
Any help is appreciated,
Paco
Program Fortran_Calls_C
Use kernel32 ! Declares Win32 API routines
Implicit None
! Declare the interface to functions in BaseCalc.dll
Interface
Function ModelClear ()
Integer ModelClear
End function ModelClear
Function ModelSetModelEOS (Model)
Integer ModelSetModelEOS
Character, Intent(IN) :: Model*7
End function ModelSetModelEOS
Function ModelSetModelCpIgStandard (CpIgStnd)
Integer ModelSetModelCpIgStandard
Character, Intent(IN) :: CpIgStnd*10
End function ModelSetModelCpIgStandard
Function ModelSetComponentName (CompIndex,CompName)
Integer ModelSetComponentName
Character, Intent(IN) :: CompName*8
Integer, Intent(IN) :: CompIndex
!DEC$ ATTRIBUTES VALUE:: CompIndex
End function ModelSetComponentName
End Interface
! De
clare variables
Integer(HANDLE) :: dll_handle
Integer(BOOL) :: free_status
Integer resModelClear, resModelSetModelEOS, resModelSetModelCpIgStandard, resModelSetComponentName
Integer i
Integer ComponentIndex
Character ModelName*7, CpIg*10, ComponentName*8
! Declare pointers to the functions.
Pointer (p_ModelClear, ModelClear)
Pointer (p_ModelSetModelEOS, ModelSetModelEOS)
Pointer (p_ModelSetModelCpIgStandard, ModelSetModelCpIgStandard)
Pointer (p_ModelSetComponentName,ModelSetComponentName)
Parameter(ModelName = 'PC-SAFT') ! The selected Model is PC-SAFT
Parameter(CpIg = 'Polynomial') ! The selected Cp model is Polynomial
Parameter(ComponentName = 'n-Hexane') ! Modeling n-Hexane as only component in the system
Parameter(ComponentIndex = 0) !
dll_handle = LoadLibrary ("BaseCalc.dll"C)
! Access function(s) in Library 'BaseCalc.dll'
p_ModelClear = GetProcAddress (dll_handle, "ModelClear"C)
p_ModelSetModelEOS = GetProcAddress (dll_handle, "ModelSetModelEOS"C)
p_ModelSetModelCpIgStandard = GetProcAddress (dll_handle, "ModelSetModelCpIgStandard"C)
p_ModelSetComponentName = GetProcAddress (dll_handle, "ModelSetComponentName"C)
100 Format(A,T60,i5)
200 Format(A,i1,A,T60,i5)
!Call function(s) and get returned value
resModelClear = ModelClear()
Write (*,100) "ModelClear returns: ", resModelClear
resModelSetModelEOS = ModelSetModelEOS(ModelName)
Write (*,100) "ModelSetModelEOS returns: ", resModelSetModelEOS
resModelSetModelCpIgStandard = ModelSetModelCpIgStandard(CpIg)
Write (*,100) "ModelSetModelCpIgStandard returns: ", resModelSetModelCpIgStandard
resModelSetComponentName = ModelSetComponentName(ComponentIndex,ComponentName)
Write (*,100) "ModelSetModelCpIgStandard returns: ", resModelSetComponentName
! Unload the library
free_status = FreeLibrary (dll_handle)
! End of main program
Pause
End Program Fortran_Calls_C



