locked
[Managed C++/ C#] #define, typedef enum, etc... RRS feed

  • Question

  • Hi,

    This question must have been asked many times, but I can't manage to find the answer...

    I have some modules written in C, and I'd like to translate 1 or 2 headers (containing typedef enum, #define, etc...) into Managed C++ to be able to use em in C#

    So, let's say I have this (C Header):

    #define _EXAMPLE_ 0x00100000
    
    typedef enum
    {
    	CODE1            = 0x00000000,
    	CODE2            = 0x00000001
    } EXAMPLE_CODE;
    
    typedef struct _example {
        struct _example *  pNextExample;
        struct _example *  pPreviousExample;
        PVOID              ExampleData;
        } EXAMPLE, * PTR_EXAMPLE;
    How can I get it there (C++ Managed), so I'll be able to use it in my C# project

    namespace ExampleMgr
    {
        ...
    }
    Thanks in advance!
    Tuesday, September 8, 2009 1:25 PM

Answers

  • public enum class EXAMPLE_CODE: int
    {
    	CODE1 = 0x00000000,
    	CODE2 = 0x00000001
    };
    
    public ref class _example
    {
    public:
    	_example ^pNextExample;
    	_example ^pPreviousExample;
    	IntPtr ExampleData;
    };

    C# only allows 'flag' #defines, so you would need something like the following to make the #define constant available:

    private ref class DefineConstants sealed abstract
    {
    public:
    	literal int _EXAMPLE_ = 0x00100000;
    };

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Marked as answer by syfffs Tuesday, September 8, 2009 3:41 PM
    Tuesday, September 8, 2009 2:48 PM

All replies

  • public enum class EXAMPLE_CODE: int
    {
    	CODE1 = 0x00000000,
    	CODE2 = 0x00000001
    };
    
    public ref class _example
    {
    public:
    	_example ^pNextExample;
    	_example ^pPreviousExample;
    	IntPtr ExampleData;
    };

    C# only allows 'flag' #defines, so you would need something like the following to make the #define constant available:

    private ref class DefineConstants sealed abstract
    {
    public:
    	literal int _EXAMPLE_ = 0x00100000;
    };

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Marked as answer by syfffs Tuesday, September 8, 2009 3:41 PM
    Tuesday, September 8, 2009 2:48 PM
  • Thanks for the straight answer!
    Tuesday, September 8, 2009 3:41 PM