我在使用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
不幸的是,我们有“现状”的情况。 –