Posted By

xXxPizzaBreakfastxXx on 12/16/14


Tagged

c Sharp c# c++


Versions (?)

C#/C++ Shared enum


 / Published in: C#
 

URL: cs_cpp_shared_enum

If you are using c++/cli or UnmanagedExports, this is a useful way to share enum int values between c++ and c# code/DLLs without worrying about duplicated code going out of date.

  1. CS:
  2.  
  3. -------------------
  4.  
  5. #if !cpp
  6.  
  7. using System;
  8.  
  9. namespace MyProject
  10. {
  11. class ECommandEnum
  12. {
  13. public //enum CommandEnum
  14. #endif
  15. enum CommandEnum
  16. {
  17. Move = 0,
  18. Wait
  19. };
  20.  
  21. #if !cpp
  22. }
  23. }
  24. #endif
  25.  
  26.  
  27.  
  28.  
  29. CPP:
  30.  
  31. -------------------
  32.  
  33. #include "whatever.h"
  34.  
  35. #define cpp (1)
  36. #include "F:\dev\MyProject\CommandEnum.cs"
  37.  
  38.  
  39. int main()
  40. {
  41. }

Report this snippet  

You need to login to post a comment.