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

Calling Visual Basic dll from Fortran

profray
Beginner
577 Views
I have found numerous discussions on calling Fortran dll from various versions of Visual Basic. However, in searching for information to call a VB dll from Fortran, the very few articles shown are no longer up. Any help or suggested articles and examples?
Many thanks in advance.
R
0 Kudos
6 Replies
anthonyrichards
New Contributor III
577 Views
This guy shows you how to create a Windows DLL in Visual Basic. The problem he had to overcome (as will you) is that VB does not normally export symbols that you can use to import into your Fortran code. He has a work around that works, as I have tried it.

http://oreilly.com/pub/a/windows/2005/04/26/create_dll.html?page=1

Link found by doing a Google search on "exporting from Visual Basic Dll"
0 Kudos
abhimodak
New Contributor I
577 Views
Hi Profray

The sailient steps are:-
(1) Create the VB dll "and" the corresponding type library. The substeps are:-

(a) Choose the project type as VB class library,
(b) By default VB will add something like Class1.vb. (You can delete this file or add other things you want; see step (c) below). You need to add a "COM" class. To do this, use Add new item --> COM class. The added COM class file will have the first line looking like (c) To the COM class you would add other things. And/or add other classes, forms etc and instantiate, call methods from etc. But make the relevant calls from a method in COM class.

(2) Using the Fortran Module Wizard to import the things exposed by the VB type library. The import would result in a module file that will encapsulate the methods from the VB dll. These will be the methods from the COM class file.

(3) In the Fortran application, add USE of the module generated in step 2.

(4) Register the VB dll on the computer you want to use it. (On you build computer, you can make this happen automatically i.e. for the VB project use properties --> Compile --> Check the checkbox Register for COM interop. Otherwise you will have to use regasm VisualBasicDLL.dll.)

For some other details check the posts by Anthony Richards, Paul Curtis, Jugloslav. I will post the links and perhaps a demo of the above procedure.


Abhi



0 Kudos
profray
Beginner
577 Views
Thanks to both posters, I will try to get on this now. The examples or other references would help, but I think I get the idea.
0 Kudos
DavidWhite
Valued Contributor II
577 Views
Does anyone have a working example of creating and calling a VB DLL from IVF?

I would appreciate it greatly.

Thanks

David
0 Kudos
anthonyrichards
New Contributor III
577 Views
I have posted code for calling a Visual Basic 2008 DLL from CVF and IVF to this thread:

http://software.intel.com/en-us/forums/showthread.php?t=78835&o=a&s=lr
0 Kudos
anthonyrichards
New Contributor III
577 Views
Here is A Visual BAsic Express 2008 clas library project that creates the class "Class2" and its class library.
When unzipped, you will have to open a command prompt, then navigate to the .../bin/release/ folder that contains the Classlibrary2.dll and then execute the following to register the DLL and the TLB on your system:

REGASM /TLB /CODEBASE Classlibrary2.dll

but only AFTER having added the path to the executable REGASM.EXE to the PATH environment, so that REGASM.EXE can be found.
If you have one of the versions v2.0.50727 or v4.0.30319 of the Microsoft .NET framework installed, you can usually find REGASM at

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ or
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\

If you haven't, they are available as a free down load from microsoft.

I attach an IVF console project that creates a Class2 object and calls its methods, one method just returns the class name, the other returns a pointer to a SafeArray of 10, 18-character strings and the Fortran program then uses Windows API functions to access the bit-strings that the SafeArray uses and to convert them to ASCII strings. It then displays them one by one.
0 Kudos
Reply