What you basically need is a way to serialize your data structure/class in a defined way, so that you can then easily transmit it over a transmission line.
This is not particular to the case of C vs C++ APIs you are referring to, but is also necessary for correct transmission of data between for instance two machines with different endianness.
There already exists a number of solutions for serializing structures, some easier to use than others. Currently I'm mainly working on a system where we use Thrift, which lets you define datatypes and structures in an easy-to-read IDL file, and can then generate files implementing these for a large number of languages, so that you can for instance very easily transfer a class from a C++ program over a network to a class in a Java program.
Other possibilities include JSON, XML, and probably a large number of others also. Since your case seems relatively simple, you can of course also just write your own - for instance by including serialize()
and unserialize()
functions, that respectively convert all member variables of your class to an array of char
(serialization), and set all member variables of your class from an array of char
(unserialization).