简体   繁体   中英

Read a C++ struct written to a file with C# code

The system we will be modifying consists of a bunch of applications that communicate via files (some write fils, others read them and so on). The applications are written in C++, one of them is now to be rewritten to C#. The problem is that this new app needs to read a file that contains a C++ struct written to it by another app using C++ fwrite. I have a C++ library that contains this struct and I guess I can reference it within my C# code but I have no control over the application producing the file.

Will it be possible, and if yes with how big an effort, to read a known C++ struct with a C# code?

How many structs and how big? It may be easier, and probably more robust, to just write your own code to read them, something like

static ReadFoo (BinaryReader reader)
{
    Foo foo = new Foo();
    foo.thing = reader.ReadInt32();
    ...
    return foo;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM