我可以通过标准::字符串一个DLL,什么我可以做DLL's? [英] I can pass std::string for a Dll and what i can do with DLL´s?

查看:87
本文介绍了我可以通过标准::字符串一个DLL,什么我可以做DLL's?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相隔code片段成一个DLL,因为这将是经常updated.And应该更容易部署。

I separated a code fragment into a DLL , because it will be frequently updated.And should be easier to deploy.

但我有什么,我能做什么,我不能用一个DLL做的问题。
我可以通过一个std:字符串到DLL,和一个CString?
我可以通过一个指向一个结构(以标准:: string的成员),并在DLL补吗?
一个dll可以返回一个指向分配有结构?这将是有效的?我以后能删除吗?

But i have a question of what i can do and what i cannot do with a Dll. I can pass a std:string to a DLL, and a CString ? I can pass a pointer to a struct(with std::string members) and fill it in dll ? Can a dll return a pointer to a struct allocated there ? It will be valid ? Can i delete it after ?

和应该怎样更好地传球,性病::字符串或CString的?

And what should better to pass, std::String or Cstring ?

谢谢!

推荐答案

您必须做出选择:


  • 紧密耦合的DLL:DLL将建成具有完全相同的编译器的版本,包装和调用约定设置,库选项作为应用程序,并且两个动态链接到运行时库( / MD 编译器选项)。这使您可以传递对象来回包括STL容器,从应用程序内分配DLL对象,其他模块中从基类派生,这样做只是不使用DLL的一切你所能。缺点是,你再也不能独立于主应用程序的部署DLL。双方必须一起建造。该DLL只是提高你的进程启动时间和工作集,因为应用程序可以启动加载DLL(使用 / DELAYLOAD 链接选项)前运行。建立时间也比单个模块更快,尤其是当使用整个程序的优化。但优化不拿整个应用程序的DLL边界的地方。任何不平凡的变化仍需要重建两个。

  • Tightly coupled DLL: The DLL is built with the exact same compiler version, packing and calling convention settings, library options as the application, and both dynamically link to the runtime library (/MD compiler option). This lets you pass objects back and forth including STL containers, allocate DLL objects from inside the application, derive from base classes in the other module, do just about everything you could without using DLLs. The disadvantage is that you can no longer deploy the DLL independently of the main application. Both must be built together. The DLL is just to improve your process startup time and working set, because the application can start running before loading the DLL (using the /delayload linker option). Build times are also faster than a single module, especially when whole program optimization is used. But optimization doesn't take place across the application-DLL boundary. And any non-trivial change will still require rebuilding both.

松散耦合:应用程序不依赖于由DLL中定义对象的类布局。您只使用高度兼容的数据类型:原始类型,指针,函数指针,以及由这些元素的用户定义类型。类从基类定义接口,没有任何数据成员,也没有非虚函数(这意味着没有构造函数,也没有共享标准库的对象,如继承的std :: string的的CString )。所有的分配和对象的创建必须通过工厂函数来完成。内存必须从分配它的模块被释放。 code和数据分开。头文件明确规定允许跨模块边界每个结构的每个导出函数和包装的调用约定。的优点是,该DLL和应用可以完全独立地更新。可以重建一个具有新的运行时库,或甚至在一个完全新的语言的新编译器的版本,并且不必连触摸其他

Loosely coupled: The application doesn't depend on the class layout of objects defined by the DLL. You use only highly compatible data types: primitive types, pointers, function pointers, and user-defined types made up of these elements. Classes inherit from a base class which defines interface and has no data members and no non-virtual functions (this means no constructors and no sharing of standard library objects such as std::string or CString). All allocation and object creation must be done through a factory function. Memory must be deallocated from the module which allocated it. Code and data are separated. The header file explicitly states the calling convention of each exported function and packing of each structure allowed to cross module boundaries. The advantage is that the DLL and application can be updated completely independently. You can rebuild one with a new runtime library, new compiler version, or even in a completely new language, and don't have to even touch the other.

我总是建议使用松散耦合的方式。

I always advise using the loosely coupled approach.

这篇关于我可以通过标准::字符串一个DLL,什么我可以做DLL's?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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