- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try setting the Visual Basic project configuration to x86 if you are calling a 32-bit Fortran dll.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Accually I could not able to reach it, could you provid me a link to it
Many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page