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

Visual Basic/IVF interoperability

CharlieG
Beginner
288 Views
Is it possible to pass user defined structure containing arrays between Visual Basic .Net and IVF. Sample code attached:

Module Module1

'This structure works but results in ugly code
Public Structure udtArgs
Dim Inputs1 As Double
Dim Inputs2 As Double
Dim z As Double
End Structure

'This is what I'd like to do but Inputs must be redimensioned in code which seems to cause problems
'Public Structure udtArgs
' Dim Inputs() As Double
' Dim Z As Double
'End Structure

Public Declare Sub DoMath Lib "p:IVF8 ProjectsInterOpDoMathDebugDoMath.dll" Alias "DoMath" _
(ByRef Args As udtArgs)

End Module

! DoMath.f90
!
! FUNCTIONS/SUBROUTINES exported from DoMath.dll:
! DoMath - subroutine
!
subroutine DoMath(Args)

! Expose subroutine DoMath to users of this DLL
!
!DEC$ ATTRIBUTES ALIAS:'DoMath'::DoMath
!DEC$ ATTRIBUTES DLLEXPORT::DoMath

! Variables
type udtArgs
real*8 inputs(2)
real*8 z
end type
type(udtArgs) Args

! Body of DoMath
Args%z = Args%inputs(1) * Args%inputs(2)

end subroutine DoMath

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(106, 104)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Calc"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(42, 26)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(12, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "X"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(74, 24)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New Syste m.Drawing.Size(56, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = "10"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(194, 24)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(56, 20)
Me.TextBox2.TabIndex = 4
Me.TextBox2.Text = "20"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(162, 26)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(12, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Y"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(150, 64)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(56, 20)
Me.TextBox3.TabIndex = 6
Me.TextBox3.Text = ""
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(86, 66)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(39, 16)
Me.Label3.TabIndex = 5
Me.Label3.Text = "X * Y ="
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 149)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Mixed Language Example"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim Args As udtArgs

Args.Inputs1 = CDbl(TextBox1.Text)
Args.Inputs2 = CDbl(TextBox2.Text)

'note array being passed to Fortran is 1 based
DoMath(Args)
TextBox3.Text = Args.z

End Sub
End Class
0 Kudos
0 Replies
Reply