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

Calling Fortran dll in VB.

usanthosh
Beginner
2,325 Views
I have a code developed in VB5 which calls a FORTRAN dll (developed & compiled in DVF 6.0). The code works well in XP. Now I have switched to Intel Digital Fortran 9.0 (in MS Dev Env. 2003) on a new XP machine. The FORTRAN dll was recompiled with IDF9. NowI get a VB5error that the .dll file is not found.

Any suggestions as to what is wrong. Thank you.
0 Kudos
16 Replies
Steven_L_Intel1
Employee
2,325 Views
Why are you using an Intel Visual Fortran compiler that is so old? 11.0 is current.

In any event, the problem is likely that the Intel Fortran run-time DLLs are not in a folder listed in the system PATH environment variable. If this DLL is to be called from VB only, you can go to the Fortran > Libraries property page and change the run-time library type to "Multithreaded (/MT)" and that should help. Otherwise, make sure that the dependent DLLs are in a folder listed on PATH. The 9.0 compiler asks you on install whether to update the system environment variables - if you say no, you'll have this problem.
0 Kudos
usanthosh
Beginner
2,325 Views
Why are you using an Intel Visual Fortran compiler that is so old? 11.0 is current.

In any event, the problem is likely that the Intel Fortran run-time DLLs are not in a folder listed in the system PATH environment variable. If this DLL is to be called from VB only, you can go to the Fortran > Libraries property page and change the run-time library type to "Multithreaded (/MT)" and that should help. Otherwise, make sure that the dependent DLLs are in a folder listed on PATH. The 9.0 compiler asks you on install whether to update the system environment variables - if you say no, you'll have this problem.
I added /mt to my fortran project's 'configuration properties/fortran/comman line' & recomplied the dll. It still has the same problem. How do I manually change the PATH to include the folder containing the DLLs?
0 Kudos
Steven_L_Intel1
Employee
2,325 Views
That was not the correct way to fix the problem. Please remove /mt from the command line field and change the "Use run-time library" property.

To change the value of PATH, right click on My Computer, select Properties, Advanced, Environment Variables. Under System variables, select PATH and click Edit. Add at the end of the string:

;C:Program FilesIntelCompilerFortran9.1IA32Lib

Don't forget the semicolon separator.
0 Kudos
usanthosh
Beginner
2,325 Views
That was not the correct way to fix the problem. Please remove /mt from the command line field and change the "Use run-time library" property.

To change the value of PATH, right click on My Computer, select Properties, Advanced, Environment Variables. Under System variables, select PATH and click Edit. Add at the end of the string:

;C:Program FilesIntelCompilerFortran9.1IA32Lib

Don't forget the semicolon separator.

I changed the path as you suggested. It still does not work.

To recap I am calling a FORTRAN dll file called EXPL.DLL (which I created & complied with IVF9) from VB. In the (VB) debug mode I checked to see that the current directory contains the EXPL.DLL before the call statement. But I still get the error that EXPL.DLL is not found.
0 Kudos
usanthosh
Beginner
2,325 Views
Quoting - usanthosh

I changed the path as you suggested. It still does not work.

To recap I am calling a FORTRAN dll file called EXPL.DLL (which I created & complied with IVF9) from VB. In the (VB) debug mode I checked to see that the current directory contains the EXPL.DLL before the call statement. But I still get the error that EXPL.DLL is not found.

It works now, at least with the dll files created using DVF-v6.0. I had to place the file called DFORRT.DLL in the system32 folder.

But this procedure does not work if my dll files are compiled using IVF 9.0. Is there a similar file that I need to copy to the system32 folder?

Thank you
0 Kudos
Steven_L_Intel1
Employee
2,325 Views
I gather you don't want to try my suggestion of changing how the DLL links. Ok.

There may be several DLLs you need, but adding the folder to PATH should work. Please download Dependency Walker, open it and drag your DLL onto its window. It should identify any run-time DLLs you are missing. These can be copied to the System32 folder, but I don't recommend it. Adding the correct folder to PATH should be sufficient. Note that you will have to restart the VB application.

It may also be that you have the incorrect path for the DLL in the VB code.
0 Kudos
usanthosh
Beginner
2,325 Views
I gather you don't want to try my suggestion of changing how the DLL links. Ok.

There may be several DLLs you need, but adding the folder to PATH should work. Please download Dependency Walker, open it and drag your DLL onto its window. It should identify any run-time DLLs you are missing. These can be copied to the System32 folder, but I don't recommend it. Adding the correct folder to PATH should be sufficient. Note that you will have to restart the VB application.

It may also be that you have the incorrect path for the DLL in the VB code.
Sorry, I did not update you:

The IVF-v9 project properties of the DLL already reads: FORTRAN- Libraries - Runtime Libraries -Debug Multithread DLL
Also I changed the path as you suggested. But the dll created in IVF-v9 still does not work.

I checked the path of the fortran dll in the VB code. It is correct. The VB works with the dll compiled in DVF-v6 if it is put in the same folder.

When I drag the FORTRAN dll into Dependency Walker I get the following message:

Warning: At least one delay-load dependency module was not found.

Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

There is a 'question mark (?) next to DWMAPI.DLL and a red arrow next to SHLWAPI.DLL and MPR.DLL.

I dont know what they mean.

0 Kudos
Steven_L_Intel1
Employee
2,325 Views
Ok - the messages you got from Dependency Walker can be ignored.

What are the Fortran compile options shown under the "Command Line" tab? Show the declaration of your Fortran routine including any !DEC$ attributes lines. Show the declaration in the VB module of the DLL.
0 Kudos
usanthosh
Beginner
2,325 Views
Ok - the messages you got from Dependency Walker can be ignored.

What are the Fortran compile options shown under the "Command Line" tab? Show the declaration of your Fortran routine including any !DEC$ attributes lines. Show the declaration in the VB module of the DLL.

The IVF-9.0 compile options under the 'Command Line' tab are:

/nologo /Zi /Od /module:"$(INTDIR)/" /object:"$(INTDIR)/" /traceback /check:bounds /libs:dll /threads /dbglibs /c

----------------
The IVF-9.0 dllfile is called TdTrnsf.dll.It's declaration lines are:

SUBROUTINE TdTrnsf(N,DEYE,VR,XV,YV,ZV,XP,YP,NDIM)

!DEC$ ATTRIBUTES DLLEXPORT,STDCALL :: TdTrnsf

!DEC$ ATTRIBUTES ALIAS :'TdTrnsf' :: TdTrnsf

C

use dfcom

implicit none

C....

INTEGER*4 N,ndim

REAL*4 DEYE

REAL*4 XP(NDIM),YP(NDIM),ZP(NDIM),VR(3,3)

REAL*4 XV(NDIM),YV(NDIM),ZV(NDIM)

.
.
.

end subroutine TdTrnsf
----------------
Thelines in the VB-5.0 code calling TdTrnsf.dll are:

Option Explicit

Private Declare Sub TdTrnsf Lib "..dllsTdTrnsf.dll" (N As Long, DEye As Single, Vr As Single, _
Xv As Single, Yv As Single, Zv As Single, XP As Single, YP As Single, NDim As Long)
.
.
.
Call TdTrnsf(NPoin, DEye, Vr(1, 1), Xv(1), Yv(1), Zv(1), XP(1), YP(1), 10000)
.
.
.
----------------

Thank you for all the help, Steve.

- Santhosh

0 Kudos
Steven_L_Intel1
Employee
2,325 Views
I don't see anything wrong there, but are you really using VB5 for this? Not even VB6? Can you create a ZIP file including the CVF-built and IVF-built DLLs and attach it to a reply here? (See below for attachment instructions.)
0 Kudos
usanthosh
Beginner
2,325 Views
I don't see anything wrong there, but are you really using VB5 for this? Not even VB6? Can you create a ZIP file including the CVF-built and IVF-built DLLs and attach it to a reply here? (See below for attachment instructions.)

The VB code (with extensive user interface) was originally developed on VB5. Now we cannot find VB6 to upgrade. VB .net, which is the current version of VB,is very different from VB5and so thereare too many changes to be made inour code in order to upgrade it.The code works on XP (Vista is a problem) and so we are satisfied for now.

I am attaching the dll files.
0 Kudos
Steven_L_Intel1
Employee
2,325 Views
For some reason, the attachments do not seem to have made it correctly onto the system. Please try again.
0 Kudos
usanthosh
Beginner
2,325 Views
For some reason, the attachments do not seem to have made it correctly onto the system. Please try again.

I am attaching it again.
I have tried to debug the VB code when I run the IVF dll file. When the VB code first encounters the dll file I get the error: 'Error-28: out of stack space'.
0 Kudos
Steven_L_Intel1
Employee
2,325 Views
So I gather then that you are no longer seeing the "DLL not found" error? Try setting the Fortran property Optimization > Heap Arrays to 0. Also, you should build a Release configuration if this DLL will be used on a different system. Both your IVF and DVF DLLs are linked to the DLL run-time libraries.

Make sure that the Fortran entry points have !DEC$ ATTRIBUTES STDCALL, REFERENCE
0 Kudos
usanthosh
Beginner
2,325 Views
So I gather then that you are no longer seeing the "DLL not found" error? Try setting the Fortran property Optimization > Heap Arrays to 0. Also, you should build a Release configuration if this DLL will be used on a different system. Both your IVF and DVF DLLs are linked to the DLL run-time libraries.

Make sure that the Fortran entry points have !DEC$ ATTRIBUTES STDCALL, REFERENCE

Thank you Stevefor all the help. Now it is working.

I did not find the line Fortran > Optimization > Heap Arrays =0. My options read Optimization= Maximum Speed & Global Optimizations = Yes. I did not change them. But I did not have the line !DEC$ ATTRIBUTES STDCALL, REFERENCE.After adding the line everything is working.

Thanks for pointing out about building the Release configuration. Now I have it.

- Santhosh
0 Kudos
Steven_L_Intel1
Employee
2,325 Views
I had forgotten that you are using 9.0 - no Heap Arrays there. The STDCALL is needed because Intel Fortran has a different default calling convention than DVF and a mismatch can lead to stack corruption. I'm glad to hear it is sorted out.
0 Kudos
Reply