在DLL中导出C ++对象

编程入门 行业动态 更新时间:2024-10-28 06:32:56
本文介绍了在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)声明该类的代码。有一些标准方法可以使用 宏来完成。参见 www.codeproject/dll/SimpleDll2 .asp 或 msdn2.microsoft/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 www.codeproject/dll/SimpleDll2.asp or msdn2.microsoft/en-US/lib...4d(VS.80).aspx Good Bye QbProg

QbProg写道: QbProg wrote: 你可以__declspec(dllexport)你要导出的每个类的成员,或者__declspec(dllexport)这个类定义。 在dll用户中您应该使用 __declspec(dllimport)声明该类的代码。有一些标准方法可以使用 宏来完成。参见 www.codeproject/dll/SimpleDll2 .asp 或 msdn2.microsoft/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 www.codeproject/dll/SimpleDll2.asp or msdn2.microsoft/en-US/lib...4d(VS.80).aspx Good Bye QbProg

参见: support.microsoft/kb/168958 相关文字:唯一的STL目前可以导出的容器是 vector。所有其他容器(即map,set,queue,list,deque) 都包含嵌套类,无法导出。 文章是最后一篇2005年9月回顾 - 我想知道它是否现在可以从DLL导出std :: map

See: support.microsoft/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写信息 新闻:uY ********************* @ bt ... "Grey Alien" <gr**@andromedawrote in message news:uY*********************@bt... >我有一个包含std :: map变量的类。我需要通过DLL导出类。这个类看起来像这样: >I have a class that contains a std::map variable. I need to export theclass 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 ++对象

本文发布于:2023-10-29 08:41:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539234.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   DLL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!