tags:

views:

138

answers:

3

Is there a tool that will take a series of C++ headers and generate a XSD and a class that will serialize the C++ to XML?

Or really what we are looking for is the simplest way to migrate data from C++ to C#? We have a library in C++ that we would like to write a GUI for in C#. Using Managed wrapper classes it seems like we will have to make wrappers for each class. Automation is the goal.

+1  A: 

A possible solution... but still requires some work!:

If you're using Microsoft Visual Studio you can use the CodeDom (http://msdn.microsoft.com/en-us/library/y2k85ax6.aspx) to parse your C++ code. You can then use T4 templates to write out C# code, or C++ functions that will serialize your C++ objects.

If you've got the 2008 version of Visual Studio you get T4 with it. For 2005 its an additional download. (http://msdn.microsoft.com/en-us/library/bb126445.aspx)

Scott Langham
+1  A: 

This would be a good starting point for serializing the C++ stuff.

http://www.boost.org/doc/libs/1_38_0/libs/serialization/doc/index.html

Scott Langham
We're giving this a try in conjunction with XSD.exe.
Jake Pearson
+1  A: 

Have you considered writing a little script to convert the C++ headers into a protocol buffer .proto file.

This transform should be relatively simple. Then C++ and c# protocol buffer implementations exist and you should be able to generate most of your c# and have a semi reasonable way of keeping them in sync as you change.

That said I would still say that, if possible making your library compile with /clr to make it trivially usable from c#. This may not be possible if other consumers of the library cannot take a dependency on the CLR runtimes of course.

ShuggyCoUk