469,889 Members | 1,274 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

MC++ wrapper code problems with return enum type.

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;



---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
Nov 17 '05 #1
2 1678
How about just defining a __value enum instead of the class?

Ronald Laeremans
Visual C++ team

<tzvika.visman@-NOSPAM-m-sys.com> wrote in message
news:uv**************@TK2MSFTNGP12.phx.gbl...
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;



---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup
engine supports Post Alerts, Ratings, and Searching.

Nov 17 '05 #2

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) ;
:
};
"tzvika.visman@-NOSPAM-m-sys.com" wrote:
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:


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Egil M?ller | last post: by
reply views Thread by Daniel Lidström | last post: by
1 post views Thread by Gurminder | last post: by
1 post views Thread by Shawn B. | last post: by
1 post views Thread by DebGuria | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.