Passing arrays from to DLL FORTRAN files

Passing arrays from to DLL FORTRAN files


Actually, this is the first time for me to try to pass arrays from 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

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 )




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.

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

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.


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.

Retired 12/31/2016

Thank you so much Stev and Curtis

It is working now, but , I could able to pass integers only from 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


Did you study the sample as I suggested? It passes an array.

Retired 12/31/2016

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

Many thanks

They are under Samples in the installed product folder. Then en_us, Fortran. Open and unzip to your desktop or another writable folder.

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today