- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 [email protected] on 12-21-2004 06:56 AM
Message Edited by [email protected] on 12-21-2004 07:56 AM
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[email protected] 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Shouldn't the VB code call Fortran with Call SimpleFortranSub(I)?
Mike D.
Message Edited by durisinm on 12-21-2004 07:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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, SecondArgumentNote 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 [email protected] on 12-21-200407:45 AM
Message Edited by [email protected] on 12-21-2004 07:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 FaddMessage Edited by [email protected] on 12-21-2004 11:25 AM
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page