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

Intel Fortran DLL for use with VB 6.0

Mark_Gracey
Beginner
703 Views

I am attempting to create a DLL in Visual Fortran 11.0.074, which is to be called from VB 6.0.

After much trailing around the internet, I have created code which, when the VB program is run gives the following error:

Run-time error '49':
Bad DLL calling convention.

This is often caused by incorrectly omitting or including the ByVal keyword from the Declare statement or the Call statement, as Visual Basic for Windows checks the change in the position of the stack pointer to detect this error.

However, as far as I can see, my declarations are correct.

As a precaution, rather than trust the defaults, I have explicitly defined characteristics associated with the call calling as well as elsewhere (eg REAL*4 instead of REAL), but with no success.

My DLL, called dll1forvb.dll, contains a subroutine, addup.f90, listed below:

! F_stdcall subroutine addup(x,y,z)
subroutine addup(x [value],y [value],z [reference])
!DEC$ATTRIBUTES DLLEXPORT :: addup
!DEC$ ATTRIBUTES ALIAS:'addup' :: addup
real*4 x, y, z
z = x + y
return
end


This is called from a VB routine, as listed below:

Private Declare Sub addup Lib "C:\\Program Files\\Intel\\DMIX\\dll1forvb.dll" _
(ByVal x As Single, ByVal y As Single, ByRef z As Single)
Sub Add_button_Click()
Dim A As Single
Dim B As Single
Dim C As Single
A = Val(Val1.Text)
B = Val(Val2.Text)
Call addup(A, B, C)
Output.Caption = "The result is " & Str(C)
End Sub

In addition, I have created a file, Dll1forVB.DEF, containing the following

; Dll1forVB.DEF - Module Definition file for Dll1forVB.FOR
;
LIBRARY Dll1forVB
Description 'Sample FORTRAN DLL to be called from VB'
EXETYPE WINDOWS XP
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE SINGLE
HEAPSIZE 1024
EXPORTS addup
subtract
WEP

However, I am not sure what purpose this serves.

The files dll1forvb.dll, dll1forvb.lib and Dll1forVB.DEF are all stored in C:\\Program Files\\Intel\\DMIX, which is listed in PATH in my environment variables.


Does anyone know what I am doing wrong?


Thanks,

Mark.

0 Kudos
1 Solution
anthonyrichards
New Contributor III
703 Views
0 Kudos
2 Replies
anthonyrichards
New Contributor III
704 Views
You are missing a STDCALL attribute. See this earlier thread:

http://software.intel.com/en-us/forums/showthread.php?t=53420&o=d&s=lr
0 Kudos
Mark_Gracey
Beginner
703 Views

Anthony,
That's exactly what I needed.
Thanks for your help,
Mark.
0 Kudos
Reply