I write a MC++ wrapper for our company internal SDK that wrote in C++ native
code for writing application with this SDK over C# and other .NET languages
and most of my SDK API function return a status code that define as a enum
type.
Do I have other option then duplicate the enum from the c++ to the C# code
and write a MC++ class that look something like this:
public __gc class ManagedDokStatus
{
public:
ManagedDokStatus(DOK_STATUS statusCode):m_statusCode (statusCode ){}
__property int get_Status()
{
return static_cast<int> (m_statusCode);
}
private:
DOK_STATUS m_statusCode;
};
The DOK_STATUS type is the native c++ enum and from the C# code I done
something like this:
Declare the following enum:
enum C#DokStatus
{
// define the same c++ native enum attributes
};
And using the API like this:
return (C#DokStatus)(dok.getSerialNumber (ref serialNumber)).Status;
---
Ronald Laeremans [MSFT] - 19 Sep 2004 20:56 GMT
How about just defining a __value enum instead of the class?
Ronald Laeremans
Visual C++ team
>I write a MC++ wrapper for our company internal SDK that wrote in C++
>native
[quoted text clipped - 48 lines]
> Our newsgroup
> engine supports Post Alerts, Ratings, and Searching.
Carl - 20 Sep 2004 07:39 GMT
My solution to that problem was to make a copy of the original enum in the
managed class (MCScan), but refer to the enum values in the unmanaged class
(CScan). That works fine for me and I use it to return these enums to C# code
as well.
This allows a change of an unmanaged enum value without the need of change
in the managed code.
But if I add or delete an enum value in the unmanaged code, I need to add
and delete it in the managed code as well. That is a disadvantage I have not
solved yet. Maybe I will check some day if it is possible to create an
assert() which just informs me if the number of enum members is different
(just as a safeguard for the developer).
public __gc class MCScan
{
public:
:
__value enum eDirections
{ StandardOrder=CScan::StandardOrder,
ReverseOrder =CScan::ReverseOrder
} ;
:
eDirections GetXdirection (void) ;
:
};
> Do I have other option then duplicate the enum from the c++ to the C# code
> and write a MC++ class that look something like this: