I need to write a DLL which can accept almost any VB5 user type, so I wrote the following simple DLL to examine the actual data passed. I then declared it as shown, created a type and passed it with with the short routine also shown below.
The results looked as expected except fot the following bug.
Double Words 17 and 18 of test 1 should be BBBBBBBB,CCCCCCCC but are garbage.
Changing the definition of the fixed length string array sa to sa(5) as string * 1 for test 2 gives expected result.
Changing the definition of the fixed length string array sa to sa(4) as string * 2 for test 3 gives one double word of garbage.
Changing the definition of the fixed length string array sa to sa(4) as string * 3 for test 4 gives three double words of garbage.
Does anyone have any clues as to where VB is putting the missing data?
$COMPILE DLL
GLOBAL sp AS LONG PTR
GLOBAL lp AS LONG PTR
GLOBAL spa AS BYTE PTR
SUB tpass(fld AS BYTE,so AS INTEGER ) EXPORT
DIM bp AS BYTE PTR
bp=VARPTR(fld)
FOR x&=0 TO 79
a$=HEX$(@bp[x&])
IF LEN(a$)<2 THEN a$="0"+a$
IF x& MOD 4 =0 THEN t$=t$+","
t$=t$+a$
NEXT
IF so >0 THEN
lp=bp
[email protected][so]
[email protected][so]
t$=t$+CHR$(13)+CHR$(10)
t$=t$+STR$(@sp[-1])
t$=t$+CHR$(13)+CHR$(10)
FOR x&=0 TO @sp[-1]-1
t$=t$+CHR$(@spa[x&])
NEXT
END IF
MSGBOX t$
END SUB
Public Declare Sub TPass Lib "testpass.dll" Alias "TPASS" (tp As Any, so As Integer)
Type newpass
i As Integer
l As Long
s As String
sa(5) As String * 2
l2 As Long
ia(4) As Integer
la(4) As Long
l3 As Long
End Type
Public np As newpass
Private Sub Command1_Click()
np.i = &H1155
np.l = &H10203
np.sa(0) = "AA"
np.sa(1) = "BB"
np.sa(2) = "CC"
np.sa(3) = "DD"
np.sa(4) = "EE"
np.sa(5) = "FF"
np.l2 = &HEEEEEEEE
np.s = "ABCDEFGHIJK, the quick etc"
np.ia(0) = &H1111
np.ia(1) = &H2222
np.ia(2) = &H3333
np.ia(3) = &H4444
np.ia(4) = &H5555
np.la(0) = &H88888888
np.la(1) = &H99999999
np.la(2) = &HAAAAAAAA
np.la(3) = &HBBBBBBBB
np.la(4) = &HCCCCCCCC
np.l3 = np.l2
TPass np, 2
End Sub
Test 1
,55110000,03020100,F87E5F00,41414242,43434444,45454646,44004400,45004500,46004600,EEEEEEEE,11112222,33334444,55550000,88888888,99999999,AAAAAAAA,74F37F00,4CF47F00,EEEEEEEE,00005083
26
ABCDEFGHIJK, the quick etc
Test2
,55110000,03020100,84315F00,41424344,45464400,45004600,EEEEEEEE,11112222,33334444,55550000,88888888,99999999,AAAAAAAA,BBBBBBBB,CCCCCCCC,EEEEEEEE,4CF47F00,E45BF500,55005083,F73A0000
26
ABCDEFGHIJK, the quick etc
Test 3
,55110000,03020100,4C3F5E00,41414242,43434444,45454300,44004400,45004500,EEEEEEEE,11112222,33334444,55550000,88888888,99999999,AAAAAAAA,BBBBBBBB,74F37F00,EEEEEEEE,A033F500,55005083
26
ABCDEFGHIJK, the quick etc
Test 4
,55110000,03020100,3C455F00,41414142,42424343,43444444,45454600,43004400,44004400,45004500,46000000,EEEEEEEE,11112222,33334444,55550000,88888888,99999999,74F37F00,4CF47F00,90E7F400
26
ABCDEFGHIJK, the quick etc
The results looked as expected except fot the following bug.
Double Words 17 and 18 of test 1 should be BBBBBBBB,CCCCCCCC but are garbage.
Changing the definition of the fixed length string array sa to sa(5) as string * 1 for test 2 gives expected result.
Changing the definition of the fixed length string array sa to sa(4) as string * 2 for test 3 gives one double word of garbage.
Changing the definition of the fixed length string array sa to sa(4) as string * 3 for test 4 gives three double words of garbage.
Does anyone have any clues as to where VB is putting the missing data?
$COMPILE DLL
GLOBAL sp AS LONG PTR
GLOBAL lp AS LONG PTR
GLOBAL spa AS BYTE PTR
SUB tpass(fld AS BYTE,so AS INTEGER ) EXPORT
DIM bp AS BYTE PTR
bp=VARPTR(fld)
FOR x&=0 TO 79
a$=HEX$(@bp[x&])
IF LEN(a$)<2 THEN a$="0"+a$
IF x& MOD 4 =0 THEN t$=t$+","
t$=t$+a$
NEXT
IF so >0 THEN
lp=bp
[email protected][so]
[email protected][so]
t$=t$+CHR$(13)+CHR$(10)
t$=t$+STR$(@sp[-1])
t$=t$+CHR$(13)+CHR$(10)
FOR x&=0 TO @sp[-1]-1
t$=t$+CHR$(@spa[x&])
NEXT
END IF
MSGBOX t$
END SUB
Public Declare Sub TPass Lib "testpass.dll" Alias "TPASS" (tp As Any, so As Integer)
Type newpass
i As Integer
l As Long
s As String
sa(5) As String * 2
l2 As Long
ia(4) As Integer
la(4) As Long
l3 As Long
End Type
Public np As newpass
Private Sub Command1_Click()
np.i = &H1155
np.l = &H10203
np.sa(0) = "AA"
np.sa(1) = "BB"
np.sa(2) = "CC"
np.sa(3) = "DD"
np.sa(4) = "EE"
np.sa(5) = "FF"
np.l2 = &HEEEEEEEE
np.s = "ABCDEFGHIJK, the quick etc"
np.ia(0) = &H1111
np.ia(1) = &H2222
np.ia(2) = &H3333
np.ia(3) = &H4444
np.ia(4) = &H5555
np.la(0) = &H88888888
np.la(1) = &H99999999
np.la(2) = &HAAAAAAAA
np.la(3) = &HBBBBBBBB
np.la(4) = &HCCCCCCCC
np.l3 = np.l2
TPass np, 2
End Sub
Test 1
,55110000,03020100,F87E5F00,41414242,43434444,45454646,44004400,45004500,46004600,EEEEEEEE,11112222,33334444,55550000,88888888,99999999,AAAAAAAA,74F37F00,4CF47F00,EEEEEEEE,00005083
26
ABCDEFGHIJK, the quick etc
Test2
,55110000,03020100,84315F00,41424344,45464400,45004600,EEEEEEEE,11112222,33334444,55550000,88888888,99999999,AAAAAAAA,BBBBBBBB,CCCCCCCC,EEEEEEEE,4CF47F00,E45BF500,55005083,F73A0000
26
ABCDEFGHIJK, the quick etc
Test 3
,55110000,03020100,4C3F5E00,41414242,43434444,45454300,44004400,45004500,EEEEEEEE,11112222,33334444,55550000,88888888,99999999,AAAAAAAA,BBBBBBBB,74F37F00,EEEEEEEE,A033F500,55005083
26
ABCDEFGHIJK, the quick etc
Test 4
,55110000,03020100,3C455F00,41414142,42424343,43444444,45454600,43004400,44004400,45004500,46000000,EEEEEEEE,11112222,33334444,55550000,88888888,99999999,74F37F00,4CF47F00,90E7F400
26
ABCDEFGHIJK, the quick etc
Comment