我在使用Option Strict時打開的二進制文件中讀取結構數據的功能有問題。複製結構數據
Public Function arh_setup(ByVal rw As Boolean) As Integer Dim retval As Integer = 0 Dim fnum As Integer = FreeFile() Dim temp As ValueType = CType(New aSetup, ValueType)
Try
FileOpen(fnum, setup_file, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Shared, Len(asT))
If rw Then
FilePut(fnum, asT, 1)
Else
FileGet(fnum, temp, 1)
End If
FileClose(fnum)
Catch ex As Exception
retval = -1
End Try
' Now is question here
' How to get data from temp to asT??
EDIT:
Solution is asT = CType(temp, aSetup)
temp= Nothing
Return retval
End Function
AST被全局聲明應當從臨時含有(正確)readed數據取數據類型aSetup(結構)的變量。
問題是如何將數據從本地temp變量複製到全局asT變量,最好是沒有循環(逐字節)或循環,如果不可能,否則?
這是如此接近VB6,你可能會稱之爲VB6。如果您只是使用內置的.NET方法(如IO.File.ReadAllBytes),則問題將不存在。 – test
不幸的是,我們有「現狀」的情況。 –