0

サードパーティのライブラリにあるクラスにバイト配列をコピーしようとしています

    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?

これも可能ですか?

これがクラスの定義です(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

2 に答える 2

0

バイト配列の各データは、属性の1つに割り当てる必要があります。基本的にあなたは次のようなことをしなければならないでしょう

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

あなたのコードで:

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?

オブジェクトに配列を割り当てることはできませんが、配列を使用してオブジェクトを初期化することはできます。お気に入り

dim anInstance as new RSI_USER_RECORD(ba)

そして、その仕事をする新しいコンストラクターを作成します。

于 2012-05-25T15:59:51.973 に答える
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
于 2012-05-25T14:04:23.260 に答える