Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

passing arrays by reference to dll

Status
Not open for further replies.

carlasilva

Programmer
Jan 6, 2003
12
0
0
PT
How can I pass by reference a two dimentional array from vb 6 to a visual fortran dll subroutine?

The array is TG() as single

Can you give me a simple example of doing so?

Thank you very much for your help.

carla
 
You can't. Fortran does not recognize the safearray structure that VB uses.
This can be solved by passing a pointer to the memory area where the data is located, the dimensions of the array and the size of the array items (4 bytes when using singles).
With this information you can recreate the array in fortran.
I have no code to do this, but I guess that you can find snipplets on the web. If not, I know that there are examples in C which should be relatively easy to translate into fortran.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Um...I think that Visual Fortran just requires you to pass the first element of the array, and figures out the rest for itself.

So, if you had Dim a(10), you would pass a(0) in the call to the Fortran DLL (assuming Option Base 0).
 
There is also a undocumented function in VB left over from QuickBasic which I use occasionaly called VarPtr(var), usage :

dim demo_variable as [variable]
dim pointer as long
pointer = VarPtr(demo_variable)

pointer now contains the address of demo_variable. I haven't tried this on XP yet...

 
merlinx You can't use varptr on an array (you can use varptrarray though - but that's a different story).

strongm passing a(0) byref would give you a pointer to the memory area of the array data - which is not enough to figure out how the multidimensional array is stored in memory, you need the dimensions and the size of the array item as well... Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
i've not done this with visual fortran, i use lahey, and i've had no problem calling my dll and just passing the array name, no()'s, and getting 1, 2, and 3-d data back.
you need to make sure that you've typed your data properly in that the fortran dll will simply fill the array ignoring what vb thinks it has. a real (kind=4) will be a single, real (kind=8) will be a double, don't use integers - use longs if you're working with integer type data and be very careful using strings, they're handled differently (at least in Lahey).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top