MC++ wrapper code problems with return enum type.

T

tzvika.visman

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;
 
R

Ronald Laeremans [MSFT]

How about just defining a __value enum instead of the class?

Ronald Laeremans
Visual C++ team
 
G

Guest

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) ;
:
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top