VB6和VC ++二进制文件读/写

时间:2012-01-12 19:13:52

标签: visual-c++ vb6

我试图在VB6中读取一个用C ++创建的二进制文件,反之亦然。

是否有任何数据类型转换我不得不担心从C ++转到VB6,反之亦然?

VB6布尔数据类型的C ++中的等价类型是什么?

这是我的C ++结构:

struct FooBarFileC
{
  long int foo;
  int bar;
};

这是我在VB6中输入的类型:

Public Type FooBarFileVB
  foo As Long
  bar As Integer      
End Type

我在vb6中读取二进制文件的代码:

Dim fooBarvb As FooBarFileVB
Dim strOptionsFileName As String
strOptionsFileName = "someFile.bin"

If Dir(strOptionsFileName) <> "" Then
  file_length = FileLen(strOptionsFileName)
Else
  file_length = 0
End If

fileNumber = FreeFile

If (file_length <> 0) Then
  Open strOptionsFileName For Binary Access Read Lock Read Write As #fileNumber
    Get #fileNumber, , fooBarvb
  Close #fileNumber
End If

foo = foobarvb.foo
bar = foobarvb.bar

我在c ++中读取二进制文件的代码:

long int foo;
int bar;
FooBarFileC cFooBar;

ifstream fin("someFile.bin", ios::binary);
fin.read((char*)&cFooBar, sizeof(cFooBar));
fin.close();

foo = cFooBar.foo;
bar = cFooBar.bar;

我在VB6中编写二进制文件的代码

foobarvb.foo = foo
foobarvb.bar = bar

If Dir(strOptionsFileName) <> "" Then
  file_length = FileLen(strOptionsFileName)
Else
  file_length = 0
End If

fileNumber = FreeFile

If (file_length <> 0) Then
  Open strOptionsFileName For Binary Access Write Lock Read Write As #fileNumber
    Put #fileNumber, , fooBarvb
  Close #fileNumber
End If

我在C ++中编写二进制文件的代码

long int foo;
int bar;
FooBarFileC cFooBar;

cFooBar.foo = foo;
cFooBar.bar = bar;

ofstream fout("someFile.bin", ios::binary);
fout.write((char*)&cFooBar,sizeof(cFooBar));

1 个答案:

答案 0 :(得分:0)

你看到这些链接了吗? VB6 data types C# data types

欢呼声,