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

Calling a CVF DLL involving a derived data type from VB.Net

mozzillo
Beginner
371 Views
My problem is about calling a CVF DLL from VB.Net. This dll involves a derived data type.
I never had problems with Visual Basic 6.0, but I really don't know how to make all this work with VB.NET.

First of all I create a very simple dll which should export a record with various data types (a fixed lenght string, a numeric value and an array along with the number of items stored in it.

	subroutine CVF_VBNET_DLL(myrecord)
	
	  !DEC$ ATTRIBUTES DLLEXPORT::CVF_VBNET_DLL
	  !DEC$ ATTRIBUTES ALIAS : "CVF_VBNET_DLL" :: CVF_VBNET_DLL
	
	
	  ! Variables
	 	integer max_npts, i
		parameter(max_npts=100)
	
	 	type t_type
			sequence
			character*(20)		mystring
			double precision	mypar
			double precision	myarray(max_npts)
			integer				npts
		end type t_type
	
		type(t_type)::myrecord
	
	  ! Body of CVF_VBNET_DLL
	  ! I fill up myrecord with some values
	  ! I want VB.NET to read the values of this record
	
	  myrecord%mystring="This is mystring"
	  myrecord%mypar=123.456
	  myrecord%npts=10
	  do i=1,myrecord%npts
		myrecord%myarray(i)=i**2
	  enddo
	
	end subroutine CVF_VBNET_DLL


I can easily use this DLL in Visual Basic 6 with the following code in a module

	Option Explicit
	
	Public Declare Sub CVF_VBNET_DLL Lib "CVF_VBNET_DLL" (myrecord As t_type)
	
	Public Type t_type
	    mystring As String * 20
	    myval As Double
	    myarray(1 To 100) As Double
	    npts As Long
	End Type


and this code in the form

	Option Explicit
	
	Private Sub Command1_Click()
	    Dim myrecord As t_type
	    Dim temp As String
	    Dim i As Long
	    
	    Call CVF_VBNET_DLL(myrecord)
	    
	    With myrecord
	        For i = 1 To .npts
	            temp = temp & .myarray(i) & vbCrLf
	        Next i
	        Text1.Text = .mystring
	        Text2.Text = .myval
	        Text3.Text = .npts
	        Text4.Text = temp
	    End With
	End Sub


How can I do the same thing using Visual Basic .NET instead of VB 6 ???
THANKS TO ANYONE WHO CAN HELP ME!!
0 Kudos
0 Replies
Reply