- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've set up a simple VisualStudio 2010 solution which contains a VB Windows Form project and a IVFComposer XE 2013 library project. The windows form has a single button on it. Here's the code for the form:
Public Class Form1
Public Declare Sub IVFTest Lib "IVFTest.dll" Alias "IVFTest" ()
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
IVFTest()
End Sub
End Class
The Fortran code is also very simple:
! IVFTest.f90
!
! FUNCTIONS/SUBROUTINES exported from IVFTest.dll:
! IVFTest - subroutine
!
subroutine IVFTest
! Expose subroutine IVFTest to users of this DLL
!
!DEC$ATTRIBUTES ALIAS:'IVFTest'::IVFTest
!DEC$ ATTRIBUTES DLLEXPORT::IVFTest
! Variables
x = 3.
y = 5.
x = x + y
! Body of IVFTest
print *, 'Hello World'
end subroutine IVFTest
I've set a break point in the IVF code on the line "x = 3." When I run the solution in debug mode and click the button the code stops on the line where I've set my breakpoint. So far, so good. Unfortunately as soon as I select F8 (single step) I get Unhandled exception at 0x77da15de (ntdll.dll) in VB_IVFTest.exe: 0xC0000005: Access Violation.
Now suppose I set a break point on a later line. Run the program again and click the button. First breakpoint is hit. If I now hit F5 (Start Debugging) the program runs to my second breakpoint as expected.
I'm using Windows 7 on a 64-bit machine.
Any idea what's happneing? Why can't I single step?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just tried following the steps you list and it works for me. I do have a couple of comments.
1) Any routine you call from VB needs to be STDCALL. In the example you show, it doesn't matter because the subroutine has no arguments, but if you added arguments you would get stack corruption on return from the Fortran routine.
2) The PRINT will be discarded as there is no console.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the comments Steve. As you probably guessed my real problem is with a more complex solution. I just threw this example together to demonstrate the issue. I must have a "confused" Visual Studio 2010. I just tried opening and debugging the application in Visual Studio 2012 and everything's back to working as expected. Thanks for confirming that it should also work in VS 2010. Looks like there's an uninstall/reinstall in my future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I did guess that this was not representative of your real application. Please take my comment about STDCALL - if your real application passed arguments to the Fortran routine, and you omitted STDCALL, this would corrupt the stack and could result in this error.

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