tags:

views:

72

answers:

3

Hello,

I've got a server written in C++ that sits at the end of a named pipe, um, serving things. The commands which can be sent to the server are defined in an enum which is located in a header file.

enum {
    e_doThing1,
    e_doThing2
    ...
    e_doLastThing
};

The value of the desired enum is put into the first byte of messages sent to the server so it knows what to do. I am now writing a C# client which needs access to the services.

Is there any way I can include the header into the C# code so I don't have to maintain the same list in two locations?

Thanks, Patrick

+1  A: 

Can you generate a copy of the file with an automated process like a pre-build step defined on the C# project? All you need to do is create a copy of the file that adds a name between "enum" and "{", I think.

Edit: Depending on what kind of interface your C++ server exposes, .NET may even be able to automatically generate an interface file. For example, if this enum were defined in a COM interface or a .NET remoting interface, I think there would be automatic means of generating the enum on the client based on the server's compiled code.

BlueMonkMN
+3  A: 

If you were to put the enum in a namespace and give it a name, you could probably just add the header file directly to the C# project.

Edited with final solution:
That way around won't work, but the reverse will - name the header a .cs and include in C# project, then #include from C++.

DeadMG
Nice idea, you don't need the namespace but you do need to rename the file as a *.cs otherwise the compiler doesn't see the enum (the enum already had a name). Shame it couldn't be that simple :(
Patrick
@Patrick: Nothing stops the C++ compiler #including a .cs file.
DeadMG
@DeadMG : Cunning!
Patrick
@Patrick: I am, really :P
DeadMG
+1  A: 

You can use managed C++ for that. Include the header in a managed C++ project and you can use it from C#.

codymanix