在c ++和c#中通过c ++头使用枚举 [英] Using enum in c++ and c# via c++ header
问题描述
我有一个用C ++编写的服务器,它位于命名管道的末尾,嗯,服务东西。可以发送到服务器的命令在位于头文件中的枚举中定义。
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
};
所需枚举的值被放入发送到服务器的消息的第一个字节,该怎么办。我现在写一个需要访问服务的C#客户端。
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.
有什么方法可以将标题包含在C#代码中,所以我不必在两个位置保持相同的列表?
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?
感谢,
Patrick
Thanks, Patrick
推荐答案
如果你把枚举放在命名空间并给它一个名字,你可能只是直接添加头文件直接到C#项目。
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.
使用最终解决方案编辑:
这样将不会工作,但反向将标题的名称.cs和包含在C#项目,然后#include从C ++。
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++.
这篇关于在c ++和c#中通过c ++头使用枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!