在DLL中导出C ++对象 [英] exporting a C++ object in a DLL

查看:87
本文介绍了在DLL中导出C ++对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含std :: map变量的类。我需要通过DLL导出

类。该课程看起来像这样:


class MyClass

{

public:

MyClass( );

MyClass(const MyClass&);


private:

MyClass& operator =(const MyClass&);


typedef std :: map< SomeKey,SomethingElseTreasureChest;


TreasureChest m_treasures;

};

I have a class that contains a std::map variable. I need to export the
class via a DLL. the class looks something like this:

class MyClass
{
public:
MyClass();
MyClass(const MyClass&);

private:
MyClass& operator=(const MyClass&);

typedef std::map<SomeKey, SomethingElseTreasureChest ;

TreasureChest m_treasures;
};

推荐答案

你可以__declspec(dllexport)你想要的每个类成员

导出,或__declspec(dllexport)类定义。


在dll用户中您应该使用

__declspec(dllimport)声明该类的代码。有一些标准方法可以使用

宏来完成。参见
http://www.codeproject.com/dll/SimpleDll2 .asp



http://msdn2.microsoft.com/en-US/lib...4d(VS.80).aspx


再见

QbProg

you can either __declspec(dllexport) every member of the class that
you want to export, or __declspec(dllexport) the class definition.

In the "dll user" code you should declare the class with
__declspec(dllimport). There are standard ways to do that using
macros. See
http://www.codeproject.com/dll/SimpleDll2.asp

or
http://msdn2.microsoft.com/en-US/lib...4d(VS.80).aspx

Good Bye
QbProg





QbProg写道:


QbProg wrote:

你可以__declspec(dllexport)你要导出的每个类的成员,或者__declspec(dllexport)这个类定义。


在dll用户中您应该使用

__declspec(dllimport)声明该类的代码。有一些标准方法可以使用

宏来完成。参见
http://www.codeproject.com/dll/SimpleDll2 .asp



http://msdn2.microsoft.com/en-US/lib...4d(VS.80).aspx


再见

QbProg
you can either __declspec(dllexport) every member of the class that
you want to export, or __declspec(dllexport) the class definition.

In the "dll user" code you should declare the class with
__declspec(dllimport). There are standard ways to do that using
macros. See
http://www.codeproject.com/dll/SimpleDll2.asp

or
http://msdn2.microsoft.com/en-US/lib...4d(VS.80).aspx

Good Bye
QbProg



参见: http://support.microsoft.com/kb/168958


相关文字:唯一的STL目前可以导出的容器是

vector。所有其他容器(即map,set,queue,list,deque)

都包含嵌套类,无法导出。


文章是最后一篇2005年9月回顾 - 我想知道它是否现在可以从DLL导出std :: map

See: http://support.microsoft.com/kb/168958

Relevant text: The only STL container that can currently be exported is
vector. The other containers (that is, map, set, queue, list, deque) all
contain nested classes and cannot be exported.

The article was last reviewed in September 2005 - I wanted to know if it
is now possible to export std::map from a DLL




灰色外星人 < gr ** @ andromeda.com写信息

新闻:uY ********************* @ bt.com ...

"Grey Alien" <gr**@andromeda.comwrote in message
news:uY*********************@bt.com...

>我有一个包含std :: map变量的类。我需要通过DLL导出
类。这个类看起来像这样:
>I have a class that contains a std::map variable. I need to export the
class via a DLL. the class looks something like this:



不,你不是。创建一个接口(具有纯虚拟指针的类),

从中派生实现,并仅共享该接口。你可以通过将接口定义放在公共头文件中来实现
。不需要

__declspec(dllexport)语句。


导出C ++类是个坏消息。 __declspec(dllexport)应该是

仅用于''extern''C"''函数。

No you don''t. Create an interface (class with pure virtual pointers),
derive the implementation from it, and share only the interface. You do
that by putting the interface definition in a public header file. No
__declspec(dllexport) statement is needed.

Exporting C++ classes is very bad news. __declspec(dllexport) should be
used only for ''extern "C"'' functions.


>

class MyClass

{

public:

MyClass();

MyClass(const MyClass& );


私人:

MyClass& operator =(const MyClass&);


typedef std :: map< SomeKey,SomethingElseTreasureChest;


TreasureChest m_treasures;

};

>
class MyClass
{
public:
MyClass();
MyClass(const MyClass&);

private:
MyClass& operator=(const MyClass&);

typedef std::map<SomeKey, SomethingElseTreasureChest ;

TreasureChest m_treasures;
};



这篇关于在DLL中导出C ++对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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