- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in '...\\FCCMod.exe'. Additional Information: A call to PInvoke function 'FCCMod!FCCMod.clsFCCDll::FCCMod' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanged signature.
Seems like they're trying to tell me what the problem is but I'm not a knowledgable enough programmer to understand the message. If anyone could help me out I'd appreciate it.
My Visual Basic Code:
Public Class clsFCCDll
'FCC Model connections
Public Declare Sub FCCMod Lib "FCCmod.dll" Alias "FCCMod" (ByVal CommonUserDataPath As String, ByVal ExePath As String)
Public Sub FCCModel(ByVal CommonUserDataPath As String, ByVal ExePath As String)
FCCMod(CommonUserDataPath, ExePath)
End Sub
End Class
My Visual Fortran Code:
!DEC$NOFREEFORM
subroutine FCCMod(strUserAppPath, strExePath)
!DEC$ATTRIBUTES ALIAS:'FCCMod'::FCCMod
!DEC$ATTRIBUTES DLLEXPORT :: FCCMod
use IFCOM
use IFCOMTY
use IFWIN
CHARACTER(256), INTENT(IN) :: strUserAppPath
!DEC$ ATTRIBUTES REFERENCE :: strUserAppPath
CHARACTER(256), INTENT(IN) :: strExePath
!DEC$ ATTRIBUTES REFERENCE :: strExePath
status = AllocConsole()
ILEN = INDEX(strUserAppPath,CHAR(0)) - 1
UserAppPath = strUserAppPath(1:ILEN)
ILEN = INDEX(strExePath,CHAR(0)) - 1
ExePath = strExePath(1:ILEN)
And much more...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for posting your code.
The unbalanced stack error was caused by the incorrect calling convention of the fortran subroutine.The VB code assumes the subroutine cleans up the stack when returning; however, the default calling convention of Fortran requires the caller clean up the stack. Then the runtime system detected the mis-matched stack pointer before/after the call. To fix this, please
Change the subroutine to STDCALL like:
!DEC$ATTRIBUTES DLLEXPORT,STDCALL :: FCCMod
For reference:
http://support.microsoft.com/kb/153586
The Mixed Language section of the IntelVIsual Compiler documentation
------
Wendy
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
------
Wendy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please elaborate on this? As I understood, it's the other way round, older versions zero-padded the Fortran strings so passing them to C-style routines wasworking (by accident), but the 12.x release may not "terminate" the Fortran string with a zero character so requires user interaction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
------
Wendy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for posting your code.
The unbalanced stack error was caused by the incorrect calling convention of the fortran subroutine.The VB code assumes the subroutine cleans up the stack when returning; however, the default calling convention of Fortran requires the caller clean up the stack. Then the runtime system detected the mis-matched stack pointer before/after the call. To fix this, please
Change the subroutine to STDCALL like:
!DEC$ATTRIBUTES DLLEXPORT,STDCALL :: FCCMod
For reference:
http://support.microsoft.com/kb/153586
The Mixed Language section of the IntelVIsual Compiler documentation
------
Wendy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That didnt happen with Windows Forms and the same DLL though...
Now I will have a nice weekend :-)
Markus

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page