C#/C++ Shared enum


/ Published in: C#
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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. }

URL: cs_cpp_shared_enum

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.