Pregunta

We have a Visual Basic 6 application that writes out a config file. From looking at the application's code, it's using a "Binary Access Write" function to write out the configuration object. I'm trying to figure out how to read these type of files in C#. Obviously I would need to build an object matching the necessary fields, but this doesn't appear to be standard object serialization that I'm familiar with. The code doesn't make it clear how the application is reading the config file and assigning values to the config object's fields.

I've tried using the BinaryReader class in C#. The config object contains mostly strings but reading the file with ReadString() is not returning properly formatted strings (I can see some recognizable text but fields are combined or truncated, along with garbage binary characters).

I'm assuming that the C# BinaryReader isn't appropriate for decoding these type of VB6 binary files. Any suggestions on how to read these?

¿Fue útil?

Solución

Fortunately Microsoft seems to provide methods to enable you to read those legacy VB6 files. You might want to check out these methods:

Otros consejos

If you don't want to decipher the format in C#, you could just create a VB6 dll that does the read/write for you. Then you can simply use the VB6 dll from C#.

There are some hints here on how to call a VB6 dll from C#: Calling vb6 dlls from c#

From the answers given in the linked question, I would personally go the COM interop route.

Unless you can find some clear documentation about what this "binary access write" format is meant to be, I would write a VB6 application which reads your files and the converts them into something more portable - XML or JSON for example.

You could easily spend a lot of time reverse engineering the file format in a way that works fine for all your test samples, but doesn't work in some corner case that is only seen on a customer site. Fundamentally, reverse engineering undocumented file formats is an annoying thing to have to do.

Of course, it could be that the file format is documented - but you may well still find it's simpler to write a VB6 conversion tool than to implement a reader in C#.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top