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

DLL passing double precision to vb6

cecio
Novice
700 Views
Hi,
i have a problem writing a fortran (CVF 6.6) to use with a vb6 app.
i need to pass a record containing dp, i4 and strings...
with integer*2, byte and string i have no problem, but when i try to pass DP i have random(?) results.
Is there something i don't know?
i tryit in two different pc and i have different result...
Thanks
Cecio
here the code..
Fortran
INTEGER*2 FUNCTION passarecord(rec)

!DEC$ ATTRIBUTES DLLEXPORT :: passarecord
!DEC$ ATTRIBUTES ALIAS:'passarecord' :: passarecord
implicit none
Type recor
integer*4 i4(4)
real(8) DP
character*10 stringa
End Type
type (recor) rec
rec.i4(1)=100
rec.i4(2)=200
rec.i4(3)=300
rec.i4(4)=400
rec.dp=1.67
rec.stringa='abcdefghil'
RETURN
END
VB code

Declare Function passarecord Lib "pcroutdll.dll" (ByRef rec As recor) As Integer
Public Type recor
i4(1 To 4) As Long
dp As Double
stringa As String * 10
End Type
---------------------------
Private Sub Command3_Click()
Dim rr As recor
i = passarecord(rr)
MsgBox rr.i4(1)
MsgBox rr.i4(2)
MsgBox rr.i4(3)
MsgBox rr.i4(4)
MsgBox rr.dp
MsgBox rr.stringa
End Sub
0 Kudos
3 Replies
Steven_L_Intel1
Employee
700 Views
Add:

sequence

after:

Type recor

in the Fortran code. You have misaligned fields and the compiler is padding them. SEQUENCE will stop it from doing so, and is a good idea when you are sharing a derived type with other languages.
0 Kudos
cecio
Novice
700 Views

Thanks Steve,

with SEQUENCE it works.

As you can see i'm a novice in mixed languages programming.....

Now i try to pass a record of n bytes, and in that record i store integer*2,integer*4,dp and strings in a way likei useCOMMON .

in VB sometimes i havecorrect results and sometimes not!

Do it depend from VB (and the record definition in it) or what?

thanks

Cecio

here the code:

VB-------

Declare Function passarecord Lib "pcroutdll.dll" (ByRef REC As recor) As Integer
Public Type recor

stringa As String * 10

i4 As Long
dp As Double

End Type

Fortran--------

INTEGER*2 FUNCTION passarecord(rec)
!DEC$ ATTRIBUTES DLLEXPORT :: passarecord
!DEC$ ATTRIBUTES ALIAS:'passarecord' :: passarecord
implicit none

Type recor
sequence
integer*1 buf(22)
End Type

integer*4 i4
real(8) Dp
character*10 str

type (recor) rec
INTEGER*1 STRINGA(10)
equivalence(str,stringa)
integer*2 i
INTENT(out) rec


str='1234567890'
i4=101
dp=1.67d0

call trs(4,i4,rec.buf(11))
call trs(8,dp,rec.buf(15))
call trs(10,stRINGA,rec.buf(1))
RETURN
END


subroutine trs(N,in,out)
integer*1 in(1),out(1)
do 1 j=1,n
1out(j)=in(j)
return
end

0 Kudos
Steven_L_Intel1
Employee
700 Views
I am not familiar with how VB arranges things in its data structures. If I wanted to diagnose this, I'd put some recognizeable values in the VB structure and then examine the bytes on the Fortran side to see what I got. It might give me a clue to see if VB is padding or perhaps putting something in "string" other than just the text (for example, it may be a pointer or have a length.)
0 Kudos
Reply