Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey everyone.

I have an enum which is shown below:

enum Open
{
     OPEN_COULD_NOT_OPEN_PORT = 1, ///< Could not open the port
     OPEN_COULD_NOT_SET_UP_PORT, ///< Could not set up the port
     OPEN_INVALID_BAUD_RATE, ///< Baud rate is not valid
     OPEN_COULD_NOT_SET_BAUD, ///< Baud rate valid, but could not set it
     OPEN_ALREADY_OPEN ///< Connection was already open
};


To use in my C# solution, I export it this way:
C#
__declspec(dllexport) enum __stdcall Open{
    OPEN_COULD_NOT_OPEN_PORT = 1,
    OPEN_COULD_NOT_SET_UP_PORT,
    OPEN_INVALID_BAUD_RATE,
    OPEN_COULD_NOT_SET_BAUD,
    OPEN_ALREADY_OPEN
};


When I call from C#, I can't access that enum?
Is there any other way to do this?

My best regards...
Posted
Comments
Albert Holguin 5-Dec-11 9:48am    
See my comment to solution 2...

You cannot export an enum (at least AFAIK). You might encapsulate the enum 'functionality' in a class and export such class (this way it would be similar to a C# enum that is, actually a class).
 
Share this answer
 
Comments
Un_NaMeD 5-Dec-11 5:07am    
Oh. I get it.
Then export the class as a function or a propety?
CPallini 5-Dec-11 5:22am    
You may export a whole class, see for instance:
http://www.codeproject.com/KB/cs/marshalCPPclass.aspx
Albert Holguin 5-Dec-11 9:49am    
That's one way to do it, but it's a lot of trouble if you're just exporting one enum.
Albert Holguin 5-Dec-11 9:50am    
Good suggestion, although probably not the easiest way to do this. +5
CPallini 5-Dec-11 13:47pm    
Thank you. BTW I agree with you.
Hi,

Look at this thread, it is talking about your issue.

c-dll-c-types-exporting[^]

It says that you don't need to export your enumerate, just include the header where it is defined.
Note that you need to tune your enum definition in your header file.

Hope that would help.

Best regards.
EL GAABEB.
 
Share this answer
 
v2
Comments
Albert Holguin 5-Dec-11 9:48am    
I was going to suggest the same thing... there's really no reason to have to export an enumeration in a compiled manner. +5
elgaabeb 5-Dec-11 9:50am    
Thx :) Albert.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900