Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2004

Tip: Looking for answers? Try searching our database.

MC++ wrapper code problems with return enum type.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tzvika.visman@-NOSPAM-m-sys.com - 07 Sep 2004 15:37 GMT
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:

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.