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

Calling Fortran-DLL from Visual-Basic 6

fobermaier
Beginner
505 Views
Hello everyone,

I'm again having trouble calling a fortran-dll from VB6:
Here is the function definition:
logical(2) function CMaToV3Mat( cFile, pMat, iOF, iOT, iDF, iDT )
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'CMaToV3Mat' :: CMaToV3Mat
!DEC$ ATTRIBUTES VALUE :: iOF, iOT, iDF, iDT
implicit none type (T_MATRIX), pointer :: pMat character(len = *) :: cFile integer(4) :: iOF, iOT, iDF, iDT end function

Here is the vb6 declaration:
Private Declare Function CMaToV3Mat _
  Lib "C:VENUSivv3bV3V3ASSSimV3MatR.DLL" ( _
  ByVal strFileName As String, ByRef hMatrix As Long, _
  ByVal lngOrigFrom As Long, ByVal lngOrigTo As Long, _
  ByVal lngDestFrom As Long, ByVal lngDestTo As Long, _
  ByVal lngLenFilename As Long) As Boolean

Compiler Options are (IVF9)
/nologo /Zi /Od /GB /module:"$(INTDIR)/" /object:"$(INTDIR)/"
  /traceback /check:bounds /libs:dll /dbglibs /winapp /c /dll

I'm getting a runtime error #49, invalid calling convention.
Any ideas?
Thanks in advance
Felix Obermaier

Message Edited by fobermaier on 10-14-2005 10:03 AM

Message Edited by fobermaier on 10-14-2005 10:10 AM

0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
505 Views
AFAIK VB6 default for externals is __stdcall, but IVF default is __cdecl. So, a STDCALL attribute should sort it out.

Also, pay attention to pMat argument; since it's a pointer, in C terms, it matches a void** (T_MATRIX**), so on VB side its equivalent (actual argument) should be an address of an integer variable which holds address of a T_MATRIX (rather than mere address of a T_MATRIX). I don't know how to spell it in VB though.

Jugoslav
0 Kudos
fobermaier
Beginner
505 Views
Thanks for the hint, Jugoslav. I've added
/iface:cvf /iface:nomixed_str_len_arg
to the command line options and now everything works fine.
Felix Obermaier
0 Kudos
Reply