0

I am trying to copy a byte array into a Class that is in a third party library

    Dim usr As New RSI_USER_RECORD
    Dim ba(RSI_USER_RECORD.RSI_LEN_USER_REC - 1) As Byte
    'populate ba here
    usr = ba 'how can I do this?

Is this even possible?

Here is the definition of the class (from Reflector)

Public Class RSI_USER_RECORD
    ' Methods
    Public Function Clone() As RSI_USER_RECORD
        Return New RSI_USER_RECORD With { _
            .pID = Me.pID.Clone, _
            .pTemplateVector = Me.pTemplateVector.Clone, _
            .authorityLevel = Me.authorityLevel, _
            .rejectThreshold = Me.rejectThreshold, _
            .timeZone = Me.timeZone _
        }
    End Function


    ' Fields
    Public authorityLevel As RSI_AUTHORITY_LEVEL = RSI_AUTHORITY_LEVEL.RSI_AUTHORITY_NONE
    Public pID As RSI_ID = New RSI_ID
    Public pTemplateVector As RSI_TEMPLATE = New RSI_TEMPLATE
    Public rejectThreshold As UInt16 = 0
    Public Const RSI_LEN_USER_REC As Integer ModOpt(IsConst) = &H10
    Public timeZone As Byte = 0
End Class
4
  • How did that class object end up in a byte array in the first place? Commented May 25, 2012 at 14:15
  • @HansPassant - I am reading a datablock from a hardware device that is returned as a byte array, each 16 byte block is a USER_RECORD Commented May 25, 2012 at 14:24
  • So it is really a structure then. stackoverflow.com/a/1936208/17034 Commented May 25, 2012 at 14:30
  • Yes it looks like a structure the object browser reports: Public Class USER_RECORD Inherits System.Object Commented May 25, 2012 at 14:50

2 Answers 2

0

Each data in your byte array have to be assigned at one of the attribute. Basically you will have to do something like

authorityLevel = byte(someIndex)
pID = byte(someIndex)
pTemplateVector = byte(someIndex)
rejectThreshold = byte(someIndex)
timeZone =byte(someIndex)

in your code :

Dim usr As New RSI_USER_RECORD
Dim ba(RSI_USER_RECORD.RSI_LEN_USER_REC - 1) As Byte
'populate ba here
usr = ba 'how can I do this?

you can not assign an array in an object, but you could use the array to initialize the object. like

dim anInstance as new RSI_USER_RECORD(ba)

and create a new constructor that will do the job.

Sign up to request clarification or add additional context in comments.

Comments

0
    Dim usr As  USER_RECORD() ' init the values
    Dim ba As  USER_RECORD() = New  USER_RECORD(usr.Length - 1) {}

    For i As Integer = 0 To usr.Length - 1
        ba(i) = usr(i) ' if USER_RECORD is value type
       'ba(i) = DirectCast( usr(i).Clone(), USER_RECORD) ' if USER_RECORD is reference type

    Next

2 Comments

The problem is that I have the data in a byte array and I want to basically do a memory copy of that into the location of my instance of USER_RECORD (which is a class)
ok, are you looking for something similar to Buffer block copy. You can check Buffer.BlockCopy but you need to extract byte array from your User_Record

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.