[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

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

Dean Mitchell

8/2/2007 3:32:00 AM

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


1 Answer

Ben Voigt [C++ MVP]

8/25/2007 6:32:00 AM

0


"Dean Mitchell" <not@this.address> wrote in message
news:u%23eH4WL1HHA.4344@TK2MSFTNGP03.phx.gbl...
> 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