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

Passing arrays from VB.net to DLL FORTRAN files

Ahmed_A_2
Beginner
982 Views

Hi 

Actually, this is the first time for me to try to pass arrays from VB.net to Dll created by FORTRAN, but I had too much difficulty to do that. Usually I'm having this error “An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)”, and I don't know why and what does it mean? .following is a very simple example I'm trying to do using VB.net:

Imports System.Runtime.InteropServices

Module Module1    

Declare Sub FortranDLL Lib "C:\Users\Shabana\Desktop\DLL Project\Dll2\VBPROG\Dll2.dll" Alias "FORTRANDLL" (<[In](), Out()> ByVal Array1() As Int32, ByRef Foo As Int32)

End Module

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

Dim I As Int32        

Dim Test As Int32() = {1, 2, 3, 4, 5, 6}        

FortranDLL(Test, Test.Length)        

For I = 0 To 5            

TextBox1.Text = Str$(Test(I))        

Next I    

End Sub

End Class

Also this is the Fortran code to create the Dll file

     

Subroutine FortranDLL( Array1, upbound )

!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'FORTRANDLL' :: FortranDLL

!DEC$ ATTRIBUTES REFERENCE :: Array1

!DEC$ ATTRIBUTES REFERENCE :: upbound    

Implicit None

! ...argument declarations    

Integer(4) :: upbound           

Integer(4) :: Array1(1:upbound)         

  Array1 = Array1 + 10

End Subroutine FortranDLL

I hope that I could able to make it clear , and I will be do appreciated if you could help me solving this problem.

0 Kudos
7 Replies
Curtis_Haase
Beginner
982 Views

Try setting the Visual Basic project configuration to x86 if you are calling a 32-bit Fortran dll.

0 Kudos
A__Valle
Beginner
982 Views

I notice that you declare the array to be passed by reference at Fortran side, while byval at the VB.Net side. This might be the cause of the error.

Dirk

0 Kudos
Steven_L_Intel1
Employee
982 Views

I suggest that you study the "VB-Calls-Fortran" sample we provide. Curtis has the answer to the error message - if you leave the VB platform default as "Any CPU", it will fail to load a native DLL on an x64 system. You must explicitly select x86 or x64 depending on the architecture of your DLL.

0 Kudos
Ahmed_A_2
Beginner
982 Views

Thank you so much Stev and Curtis

It is working now, but , I could able to pass integers only from vb.net to the dll file , but I can not pass arrays , could you please provide me some thing to help me in that

I do appreciate your help

Ahmed

0 Kudos
Steven_L_Intel1
Employee
982 Views
Did you study the sample as I suggested? It passes an array.
0 Kudos
Ahmed_A_2
Beginner
982 Views

Accually I could not able to reach it, could you provid me a link to it

Many thanks

0 Kudos
Steven_L_Intel1
Employee
982 Views
They are under Samples in the installed product folder. Then en_us, Fortran. Open MixedLanguage.zip and unzip to your desktop or another writable folder.
0 Kudos
Reply