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

Calling IVF DLL from Visual Basic in VS2010

polarbear00
Beginner
935 Views
Hi Everyone,
I just started using VS2010 with IVF, I am trying to build a very simple DLL as below and call it from VB (in VS2010). It builds OK, I don't get any error, the problem is that nothing happend when I pass the call to IVF DLL, I expect a to change from 2 to 5, but it stays 2. the other question is how can I debug IVF DLL part. I was used work with VB6, CVF and there I just introduced VB .exe file as an external file for CVF in order to debug DLL part.

Thanks

************* IVF Part ************
subroutine Dll1(a)
implicit none
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL :: Dll1
!DEC$ ATTRIBUTES ALIAS:'Dll1' :: Dll1
Doubleprecision :: a
a=5.0;
return
end !subroutine Dll1

************* VB Part **************
Public Class Form1
'Declare Sub Dll1 Lib "C:\\VSPractices\\WindowsApplication1\\Dll1\\Debug\\Dll1.dll" (ByVal a As Single)
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Double
a = 2
Call Dll1(a)
End Sub
End Class

Module Module1
Public Declare Auto Sub Dll1 Lib "C:\\VSPractices\\WindowsApplication1\\Dll1\\Debug\\Dll1.dll" _
(ByVal a As Double)
End Module


0 Kudos
6 Replies
netphilou31
New Contributor III
935 Views
It simply due to the fact that the argument is passed by value instead of reference (Byref). In the fortran code you need to change the line:
[fortran]!DEC$ ATTRIBUTES DLLEXPORT, STDCALL :: Dll1[/fortran]
by
[fortran]!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE :: Dll1[/fortran]
and the VB declaration:
[vb]Public Declare Auto Sub Dll1 Lib "C:VSPracticesWindowsApplication1Dll1DebugDll1.dll" _
    (ByVal a As Double)[/vb]
by
[vb]Public Declare Auto Sub Dll1 Lib "C:VSPracticesWindowsApplication1Dll1DebugDll1.dll" _
    (ByRef a As Double)[/vb]
0 Kudos
polarbear00
Beginner
935 Views
Thanks, the problem was resolved. I am also trying to debug from IVF DLL, when I put a breakpoint there it does not go in and a yellow exclamation mark appears that says "the breakpoint will not currently be hit. no symbols have been loaded for this document". do you have any clue how to get into the IVF DLL part in debug mode?

Regards
0 Kudos
netphilou31
New Contributor III
935 Views
You need to use the Debug configuration for the Fortran Dll and you need to start debugging from the Fortran project (you have to configure the main program to run when debugging in the fortran project properties window : "Debugging" section and on the right side just fill the "Command" field, you can also define here the "Working directory").
0 Kudos
polarbear00
Beginner
935 Views
Thanks for the help, It worked.
0 Kudos
polarbear00
Beginner
935 Views
Does IVF have auto-complete feature? is there any add-ons that does that?

Thanks
0 Kudos
Steven_L_Intel1
Employee
935 Views
No it does not.
0 Kudos
Reply