read/write binary files for different languages

Started by
4 comments, last by ArchG 18 years, 8 months ago
i've developed my own map format that is written as a binary file however my game is being written in c++ and the program that writes the maps is made in VB6 and from what i've seen it appears that binary files are written differently in vb so i was wondering, how i could get vb to write the binary file the same way as c++ does?
Advertisement
Write it byte for byte. I have little (or none) experience with the late VB's. But if your getting different data, I can only assume that it uses UTF-8 per default.

If you make sure you only write a char at time, there should be no difference in how the file is stored. Im also guessing that it might have some different ways of storing strings. Only guessing though, but that would be the first thing I'd check.

Have you tried looking over what data is being stored?
Domine non secundum peccata nostra facias nobis
You could always build a COM object in C++ and then just use that COM object in VB. For something as simple as writting/reading binary files it should be pretty easy.

~guyaton
~guyaton
Private Type randomstruct
x As Single
y As Single
End Type

...

Open "C:\a.txt" For Binary As #1
Dim x As Long, v As String, t As randomstruct
v = "blah"
x = 5
t.x = 1
t.y = -35
Put #1, , x 'This will write the bytes 05 00 00 00
'That is how a 32-bit "Long" is stored in memory
'(little-endian)
Put #1, , v 'This will write the 4 bytes in the string "blah"
Put #1, , t 'This will write the 4 bytes in x and then the 4 bytes in y stored as 32-bit floats ("Singles") are stored in memory. (Theres some IEEE standard)
You could always create a converter, have VB output to text should be possible but it will make it bigger, then create a C++ program to convert it. When I have my own file formats I usually do this anyway just because in my cases exporting the information is easy but maybe not in the proper arragment I would like for easy loading so I create a converter program to arrange it so I can load in everything very fast and easily.

-THACO
What you have to do is write the file in Sequential Order, that's how C++ does it..

I had kind of a similar question a while ago and posted about it..maybe that thread will help..

Thread


At the end I post an example how I did it, you may have to switch to VB.net to do it exactly how I did it, but that shouldn't matter...check it out and let me know if that helps ya at all

ArchG

This topic is closed to new replies.

Advertisement