- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just when I thought I had the interfaces down between my C++ program and a Fortran DLL, I get this message on returning to the C++ program:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
Basically here's the setup:
C++ code:
typedef void (*FortranFunction)(assorted float*, int*, float, int and one char* followed by unsigned int for hidden string length parameter)
Fortran code:
subroutine FortranFunction (parameter list ending with the string)
!MS$ ATTRIBUTES DLLEXPORT :: FortranFunction
USE IFPORT
USE ISO_C_BINDING
integer(C_INT), value, intent(IN) :: x
real(C_FLOAT), dimension(x), intent(IN) :: data_block
yada, yada, yada
character*(*), intent(IN) :: string
...
return
end subroutine
Any suggestions on best approach to finding and fixing this problem will be greatly appreciated.
Dick
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I do when tracking such issues is to watch the value of ESP around all calls in the suspect code and see where it is not being properly reset. If you are using STDCALL somewhere, this can definitely cause a stack problem if not done properly. With the C mechanism, the stack should be popped with an add instruction after the call.
The most common cause of this problem is inconsistent C-STDCALL declarations. It could be in a routine called by your Fortran function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
Thanks, I watched the return from the disassembly window and saw that the Fortran DLL was clearing the stack unlike a test app I had written to test out fixes. I looked at the external procedures setting in the DLL's properties and found it was CVF. The DLL is legacy code and was built using Digial Visual Fortran. I changed it to C, REFERENCE and the problem went away - now I just have to fix an old C utilities file that was using stdcall.
Thanks for your help on this over the last week or so. Hopefully I won't be bugging you any more.
Dick
![](/skins/images/05E44345FCD0BEE6CE9B856B313C05B1/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page