vb.net - 如何从 vb.net 中的二进制文件中读取 vb6 定长字符串
问题描述
语境
我有一个使用这种特定类型的vb6软件:
Type Example
A As Integer
B As Single
C As String * 10
D As Byte
E As String
End Type
这个结构完全保存在一个带有简单“ put ”的二进制文件中:
Dim Numfile%
Numfile = FreeFile
[...]
Put #Numfile, , example_instance
[...]
问题
现在我想从vb.net (.NET Framework 4) 读取这个二进制文件。问题是在.net中我们没有固定的字符串......我试图写一些类似的东西:
Structure Example
Dim A As Short
Dim B As Single
Dim C() As Char ' ---> This should replace String * 10.
Dim D As Byte
Dim E As String
End Structure
然后我阅读了文件:
Dim n as short = FreeFile()
Dim instance as Example
If FileExists(filename) Then
FileOpen(n, filename, OpenMode.Binary, OpenAccess.Read)
[...]
FileGet(n, instance)
[...]
但是,很明显,原始数据没有被正确检测到。
如何在 vb.net 中正确读取此二进制文件?
解决方案
我会写这个作为答案,即使我不能 100% 确定它会起作用,因为这不是我曾经做过的事情。该VBFixedString
属性专门用于 VB6 将使用固定长度的情况String
。因此,我认为像这样声明你的类型:
Structure Example
Dim A As Short
Dim B As Single
<VBFixedString(10)> Dim C As String
Dim D As Byte
Dim E As String
End Structure
应该做的伎俩。
推荐阅读
- java - firebase getValue 方法没有从节点检索值,因为它应该
- c - GDB 跳过共享库断点
- javascript - ReplaceAll 清理字符串
- r - 如何在 flexdashboard 的传单地图中调整弹出图像的大小?
- xss - 使用 XSS 在标头中使用 x-csrf 令牌绕过 CSRF 保护
- python - 字符串操作、数据处理、正则表达式
- amazon-web-services - 关于设置 Cognito 以登录 S3 网站的问题
- java - Activity 关闭时不调用 IntentService.onDestroy()
- pytorch - 从 SYFT 安装 PATE 时出现错误
- python - 如何将python字典替换为具有相同键的QueryDict