Passing arrays from VB.net to DLL FORTRAN files

Passing arrays from VB.net to DLL FORTRAN files

imagem de Ahmed A.

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.

8 posts / 0 new
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.
imagem de Curtis Haase

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

imagem de D.W. van Meeuwen

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

imagem de Steve Lionel (Intel)

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.

Steve
imagem de Ahmed A.

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

imagem de Steve Lionel (Intel)

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

Steve
imagem de Ahmed A.

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

Many thanks

imagem de Steve Lionel (Intel)

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.

Steve

Faça login para deixar um comentário.