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

Help making a dll

tmadden
Beginner
772 Views
I'm calling an IntelFortran dll from VB6, and I get the error message : "Bad dll Calling Convention"on the line that calls the dll.
WhenI debug the program, the dll does operate on the integer, but then it gives the error. I've included all my code. This is my first attempt at a dll, so sorry in advance if its a simple question.
Code:
VB Form 1:

Option Explicit
Private Sub Command1_Click()
Dim I As Integer
I = 20
MsgBox (I)
SimpleFortranSub I
MsgBox (I)
End Sub

VB Module1:

Option Explicit
Declare Sub SimpleFortranSub Lib "C:dev2EXAMPLESimpleFortranSub.dll" (ByRef I As Integer)

Fortran DLL:

subroutine SimpleFortranSub (TestInt)
  !DEC$ ATTRIBUTES DLLEXPORT::SimpleFortranSub
  !DEC$ Attributes alias : "SimpleFortranSub" :: SimpleFortranSub
  Integer*2 TestInt
  TestInt = TestInt + 1
end subroutine SimpleFortranSub


Message Edited by tmadden@linkamericacorp.com on 12-21-2004 06:56 AM

Message Edited by tmadden@linkamericacorp.com on 12-21-2004 07:56 AM

0 Kudos
5 Replies
durisinm
Novice
772 Views


tmadden@linkamericacorp.com wrote:


I'm calling a Fortran dll from Visual Basic, and I get the error message : "Bad dll Calling Convention"on the line that calls the dll.


WhenI debug the program, the dll does operate on the integer, but then it gives the error. I've included all my code. This is my first attempt at a dll, so sorry in advance if its a simple question.



Code:
VB Form 1:

Option Explicit
Private Sub Command1_Click()
Dim I As Integer
I = 20
MsgBox (I)
SimpleFortranSub I
MsgBox (I)
End Sub

VB Module1:

Option Explicit
Declare Sub SimpleFortranSub Lib "C:dev2EXAMPLESimpleFortranSub.dll" (ByRef I As Integer)
Shouldn't the VB call the DLL with Call SimpleFortranSub(I)?

Mike D.
0 Kudos
durisinm
Novice
772 Views

Shouldn't the VB code call Fortran with Call SimpleFortranSub(I)?

Mike D.

Message Edited by durisinm on 12-21-2004 07:35 AM

0 Kudos
tmadden
Beginner
772 Views

Thanks for taking a look. I believe either method should work fine.

From the VB6 Help Files:

"There are two ways to call a Sub procedure:

' Both of these statements call a Sub named MyProc.
Call MyProc (FirstArgument, SecondArgument)
MyProc FirstArgument, SecondArgument

Note that when you use the Call syntax, arguments must be enclosed in parentheses. If you omit the Call keyword, you must also omit the parentheses around the arguments. "

Message Edited by tmadden@linkamericacorp.com on 12-21-200407:45 AM

Message Edited by tmadden@linkamericacorp.com on 12-21-2004 07:45 AM

0 Kudos
Steven_L_Intel1
Employee
772 Views
When using Intel Fortran, you need to add the STDCALL and REFERENCE attributes to the Fortran routine to make it match what VB is looking for.
0 Kudos
tmadden
Beginner
772 Views
Thanks for the help.
I restarted using your advice, and it worked!
Code:
Mod:
Private i As Integer
Declare Sub Fadd Lib "C:dev2FCallF.dll" (i As Integer)

Form:
Private Sub Command1_Click()
Dim iVB As Integer
iVB = 20
Fadd iVB
MsgBox (iVB)
End Sub

Fortran DLL:
subroutine Fadd(i)
    !DEC$ ATTRIBUTES DLLEXPORT, Alias: "Fadd" :: Fadd
    !DEC$ ATTRIBUTES STDCALL :: Fadd       
    Integer*2 i
    !DEC$ ATTRIBUTES REFERENCE :: i
    i=i+1
end subroutine Fadd

Message Edited by tmadden@linkamericacorp.com on 12-21-2004 11:25 AM

0 Kudos
Reply