Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortan DLL call from VB

Status
Not open for further replies.

ccrum

Electrical
Apr 20, 2001
17
I have a fortran DLL I'm trying to call for a VB main exe. The call goes fine, but control is never transfered back from the the Fortran DLL. I'm trying to return an array of numbers. I know the DLL is working because I printed the array from the Fortran into a text file as a check. This occurs alomst instantaneously and is the last stpe in the DLL, but control is never returned. Instead if I try to click on something else in the VB application I get an invalid page fault error and everything crashes. Any ideas? BTW, I've tried doing it without the array and JUST printing the results. I get the same thing. Control is never returned. I'm passing all variables by reference. I'm using COmpaq DVF 6.4 and VB 5.
 
Replies continue below

Recommended for you

You need to be real careful of how data is passed to be sure everything is compatible. Lahey suggested not even trying to pass character/string data. Numbers should be passable, but you must still be careful. You might try your program without passing any data back and forth. If that works... you need to review the data you are passing. I suggest emailing Digital's support or asking in the CLF ( computers.language.fortran ) newsgroup on Usenet. Lots of people there can probably answer your question, especially Steve Lionel who works for Digital.

Dan :)
 
Dan,

Thanks for the reply. I got the program working. I really didn't change much, but added input and output declarations to the variables being passed. That seemed to do the trick. I love fortran because it's so simple and fast and VB is easy to write GUI's. If you can get it working together it makes for pretty powerful programs. Thanks again.

Cameron
 
Cameron,
I'd be interested in seeing your solution to the DLL problem. I'm working on turning an old FORTRAN code into a DLL with a VB front-end,and I have quite a bit of interactive I/O that needs to be passed back and forth from VB to the FORTRAN.

Rob

 
staudro,

What version of Fortran are you using? There are subtle things in each compiler and language version that make this a harder task than it really should be. I use DVF 6.5 now and can really only give you tips on writing DLL's using this. Let me know and I'll be happy to help if I can.

Cameron
 
Help Please,

I'm using Lahey Fortran 95 and have made a dll file to be accessed from my VB program as given by the Lahey documentation. Unfortuantely it does not cover arrays. I am unsure how to call a Fortran subroutine that contains arrays (the VB program crashes on me).

Fortran Code:

subroutine loadall(node)
implicit none
dll_export loadall
DOUBLE PRECISION, PARAMETER :: &
stepsize = 0.01

INTEGER, PARAMETER :: &
maxindex = 1/stepsize, &
threshold = 0.3/stepsize

double precision, INTENT(out) :: &
node( &
-1 : maxindex-threshold+1, &
threshold-1 : maxindex+1, &
-1 : maxindex-threshold+1,2,2)
INTEGER :: i, j, k, temp(2), phase(2)

node = DBLE(0)

OPEN (1, file = "shell.dat", status = "old")
do i = 0, maxindex-threshold+1
do j = threshold-1, maxindex-i
do k = 0, maxindex-i-j
READ(1, fmt = "(2(b25,b8))") &
temp(1), phase(1), &
temp(2), phase(2)
node(i,j,k,1,:) = DBLE(temp)/1000
node(i,j,k,2,:) = DBLE(phase)
end do
end do
end do
CLOSE(1)
RETURN
END subroutine loadall

VB Code:

Private Declare Sub loadall Lib "C:\chemapp project\ashcalcvb\vbashcalc.dll" (ByVal node As Variant)

Private Sub Form_Load()
Dim node As Variant
node = Array(-1, 1, 1, 2, 2)
Call loadall(node)


End Sub

Does anyone have some ideas about what I could be doing wrong ?

Thanks in advance,

Shannon.
 
I'm not that up on Fortran 95, but it looks like the key elements are there. It appears that your problems are in your VB.

First it looks like your VB declare may have some problems. Fortran has no idea what a variant variable type is. Also, if you are passing strings, good luck, I've never had much success with passing strings. If passing numbers, then you have to spell it out. Remember declarations in Frotran and VB are different. For instance an integer in Fortan is a Long in VB, a Real is a Single and so on. Go by byte lengths to match variable types. Also, it will work much better if you pass by reference than by value. In fact, I believe arrays must be passed by reference.

Second, you will not be able to use the Array() Function since you cannot pass a variant to Fortran. Also, I would rethink using a 5 dimensional array if you can avoid it. You will need to create an array of doubles since you are declaring some of the elements of your array "node" in fortran as doubles. Something like the following:

Declare Sub loadall Lib "C:\chemappproject\ashcalcvb\vbashcalc.dll" (node As Double)
Private Sub Form_Load()
Dim node(-1 to x, 1 to x, -1 to x, 1 to 2, 1 to 2) As Double
'x will need to be defined as your upper limit. You must have a static array.

'Since you are not passing any variables to Fortan you can go straight to the call
Call loadall(node(-1,1,-1,1,1))
' now put some code to process the values or graph them or what ever you intend to do
End sub

Notice I only passed the first element of the array. This acts as a pointer to the array in memory. I pass arrays to several different Fortran DLL's this way and never have a problem. Of course I'm using DVF, not 95 so it may be different. Also, I've never passed multidimensional arrays so I'm not sure how that will turn out. Hope this helps.

Cameron
 
Rob (staudro),

I'm not familiar with Absoft but I'll help if I can. What are the problems you are having? If you want to take this offline e-mail me at c-crum@waveconceptsintl.com. I need to tell you up front that I cannot release any of my source code. It is all owned by my company, but I can try to help with your issues or send you simple examples.

Cameron
 
Help me please:
I am trying to pass a user defined string double array from vb exe to a fortran dll. When I pass it by reference with the (1,1) "First Element". Only the first string is passed. The elements in the character array (in the Fortran are just junk). Is there a way to pass to string arrays between visual basic and digital fortran. I have taken care of defining string arrays to start from element 1 (instead of default '0') and the lengths of arrays are the same.
Can anyone help me with the issue?

Thanks in advance,
Satya
 
Hello All
I have been trying to run a fortran code exe from my asp page through a dll which in turn passes on commandline arguments to my fortran exe. I get weird errors like truncated output files when i run the code thro asp ( thro dll or straight from shell in asp script) Strangely the exe runs fine otherwise. Any pointers as to be what may be going wrong ?
Thankx a ton for your time

Sumeet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor