We help IT Professionals succeed at work.

Public Byte() in DLL

wailqill
wailqill asked
on
Hi all.
I'm writing a DLL in VB6 that's supposed to have a global variable that is to be set from the user of the DLL to a Byte() (type 8209) (ie a BLOB from a DB).
this file is to be written to disk later on in the DLL.

the problem is that i can't make a

Public Bin() as Byte

in the DLL since VB doesn't allow that.
so have to make a Variant of it.

ok so far so good.
an later on when I'm writing it to disk. I'm using the Bin-var as a Byte(), but that's when something goes wrong.

so my plain simple quastion is, How do I recieve a Byte() into a public variable in a VB-DLL?

.glenn
Comment
Watch Question

Commented:
You can try this.

' Member variable for Bin property
Private m_Bin() As Byte
' The Bin property Get
Public Property Get Bin() As Byte()
    Bin = m_Bin
End Property
' The Bin property Let
Public Property Let Bin(ByRef newValue() As Byte)
    m_Bin = newValue
End Property

Author

Commented:
yep. that solved a bit of my mystery. i can't understand that i doesn't even tried that :)

well, but now VB behaves most orrationally to me i think. look at this:

Dim f As New Object1.Class1
f.BinarySWT = rs("blob")   ' 8209 as type on both

....

Public Property Let BinarySWT(ByVal vData As Variant)
    If (VarType(vData) = 8209) Then
        Debug.Print "vData=" & VarType(vData)
        Debug.Print "lc_BinarySWT=" & VarType(lc_BinarySWT)
        ReDim lc_BinarySWT(UBound(vData))                        <-   type mismatch
        lc_BinarySWT = vData
    Else
        Err.Raise 666, , "BinarySWT only takes a bytearray as argument"
    End If
End Property

what happens here is that I take a BLOB from SQL (byte-array (8209 as typeID)). and wants to assign it to f.BinarySWT.

but i get a type mismatch on the redim. and if i don't have the redim there i get it on the row below. BOTH is of type 8209, so don't get this.

Author

Commented:
ok, i found out the solution some days ago.

the problem is that VB can't handle pointers (at least not so that the user might use them) and if an object IS a pointer, VarType returns the objectID of the DEFAULT property of the referensed object.

therefore when i do VarType(rs("blob")) I get the id 8209. but that isn't right, since it's an pointer to the RS-field.

so the very simple solution is:

[Object].BinarySWT = rs("blob").GetChunk(rs("blob").ActualSize)

this return a REAL Byte() with the full size  of the content.
CERTIFIED EXPERT
Author of the Year 2009

Commented:
wailqill, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
Per recommendation, points refunded and question closed.

Netminder
CS Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.