Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29237 Discussions

Passing allocatable arrays b/w VB and Fortran (2nd try)

jond
Novice
536 Views
Hello,
I tried to post this message earlier but it doesn'tlook likeI succeeded. I apologize if this try turns out to be a repetition.
I am trying to create a Fortran DLL that can be linked to routines written in Visual Basic as well as Fortran. The DLL uses allocatable arrays that are allocated and populated inside the DLL and then exports them to the calling routine. I was able to link the DLL to a Fortran main program and run it successfully. When I try to call it from a VB program, it doesn't work. My question is: Is it possible to specify a dynamic array inVB, then pass it to Fortran subroutine, allocate and populate it in the Fortran subroutine and then pass it back to VB? Is this possible at all?
I am using CVF v6.6.c. Thanks for any help.
John
0 Kudos
2 Replies
g_f_thomas
Beginner
536 Views
Yes, it is possible using a variety of approaches. The issue has been discussed here many times since DVF first appeared. You might want to search through the forum's archieval posts to see how others have handled the task. It's not complicated but it is oblique if only because VB is COM based and deals with SAFEARRAYS while Fortran doesn't but can. BTW, dynamic arrays are to VB what allocatable arrays are to Fortran and can be exchanged subject to the vagaries of both languages' treatment of arrays.

Good Luck,

Gerry T.
0 Kudos
rahzan
New Contributor I
536 Views
Create a com-dll in cvf (where you can do so easily using the wizid).
in the interface of your cvf dll (as designed on the com-wizid) be sure to check the assumed-size.
in vba use dim and redim to allocate arrays and pass as usual.
Also you must decide if you want in-process(faster/less crash-proof) or outta-process(slower/more crash-proof) before hand. You will be asked when you first create the com-wizid.
Finally, Don't forget the dll needs to be registered using regsvr32:
[libname].exe /REGSERVER for outta-process
regsvr32 [libname].dllfor in-process
thenin VB/A look under Tools/Ref's, and check the library for use.
0 Kudos
Reply