- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Intel Comunity
I am trying to run or calling a dll in VB6, my FORTRAN listing is:
SUBROUTINE fsub (x [VALUE])
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:'fsub' :: fsub
INTEGER*4 x
x = x + 1
END SUBROUTINE fsub
integer*2 FUNCTION ffunc (y )
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:'ffunc' :: ffunc
INTEGER*2 y
ffunc = y + 1
END function ffunc
SUBROUTINE fstring (fstr)
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:'fstring' :: fstring
CHARACTER*20 fstr
fstr = 'Juan el bueno'
END SUBROUTINE fstring
Linker line:
/OUT:"Debug/Dll6.dll" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"D:Basura2Dll6Dll6debugdll6.dll.intermediate.manifest" /DEBUG /PDB:"Debug/Dll6.pdb" /SUBSYSTEM:WINDOWS /IMPLIB:"$(OUTDIR)/Dll6.lib" /DLL
And my VB code is:
Public Class Form1
Public Declare Sub fsub Lib "D:Basura2Dll6Dll6Debugdll6.dll" (ByRef x As Long)
Public Declare Function ffunc Lib "D:Basura2Dll6Dll6Debugdll6.dll" (ByRef n As Integer) As Integer
Public Declare Sub fstring Lib "D:Basura2Dll6Dll6Debugdll6.dll" (ByRef fstr As String)
Dim text1, text2
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lngTest As Long
lngTest = CLng(Val("5"))
Call fsub(lngTest)
MsgBox(CStr(lngTest))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim intCheck As Integer
intCheck = CInt(Val("8"))
intCheck = ffunc(intCheck)
MsgBox(CStr(intCheck))
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim fstr As String
fstr = Space$(20) ' Pad string before making call.
Call fstring(fstr)
MsgBox(fstr) ' Display the results.
End Sub
End Class
The first 2 subroutines work well by the third have problems with passing the string an give me the next error message:
The runtime has encountered a fatal error. The address of the error was at 0x7a0b317c, on thread 0xb64. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshalin g errors for COM-interop or PInvoke, which may corrupt the stack.
Thanks for your help
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Two things.
In the Fortran routine fstring, add:
!DEC$ ATTRIBUTES REFERENCE ::fstr
Putting REFERENCE on the routine declaration is not sufficient - you need to tell the compiler to not expect a length to be passed.
In the VB declaration for fstring, use ByVal for the fstr argument. If you don't, you get, I think, a BSTR which you need different Fortran code to decipher.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page