如何从dll导出枚举 [英] How to export an enum from dll

查看:201
本文介绍了如何从dll导出枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我有一个枚举,如下所示:

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
};



要在我的C#解决方案中使用,我可以通过以下方式导出它:



To use in my C# solution, I export it this way:

__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
};



当我从C#调用时,我无法访问该枚举?
还有其他方法吗?

最好的问候...



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

My best regards...

推荐答案

您不能导出enum(至少是AFAIK).您可以将enum的功能"封装在一个类中并导出此类(这种方式类似于C#枚举,实际上是一个类).
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).




看看这个线程,它正在谈论您的问题.

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

它说您不需要导出枚举,只需在定义它的标题中包含它即可.
请注意,您需要在头文件中调整枚举定义.

希望对您有所帮助.

最好的问候.
EL GAABEB.
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.


这篇关于如何从dll导出枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆