HighTechTalks DotNet Forums  

Exposing a c++ enum in a managed c++ assembly

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Exposing a c++ enum in a managed c++ assembly in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Dean Mitchell
 
Posts: n/a

Default Exposing a c++ enum in a managed c++ assembly - 08-01-2007 , 11:32 PM






Hi everyone,

We have a c++ server application that we are writing a GUI client
application for. To save our time and to avoid duplicating all the code and
functionality that already exists in c++ classes I am building a managed c++
assembly around these classes so that a c# program can use them.

The problem is that alot of these c++ classes use enums, I would like to
make these visible to the c# application but I cannot find a way to do this.
Do I have to duplicate them so that I have one lot for C++ and the other for
dotnet? There must be an easier way?

Thanks for your time
Regards
Dean Mitchell



Reply With Quote
  #2  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: Exposing a c++ enum in a managed c++ assembly - 08-25-2007 , 02:32 AM







"Dean Mitchell" <not (AT) this (DOT) address> wrote

Quote:
Hi everyone,

We have a c++ server application that we are writing a GUI client
application for. To save our time and to avoid duplicating all the code
and functionality that already exists in c++ classes I am building a
managed c++ assembly around these classes so that a c# program can use
them.

The problem is that alot of these c++ classes use enums, I would like to
make these visible to the c# application but I cannot find a way to do
this. Do I have to duplicate them so that I have one lot for C++ and the
other for dotnet? There must be an easier way?
Put the innards of the enum into a separate header file, then #include it
twice:

enum NativeEnum {
#include "enum.h"
};

enum class ManagedEnum {
#include "enum.h"
};

Or, someone else had a really nifty idea.

Write the enum in native form, then it's also a valid C# file. So your
native C++ code contains:

#include "enum.cs"

The C# code just has that file included in the project. If you want the
enum to be public in C#, you'll end up with something like:

#define public
#include "enum.cs"
#undef public



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.