<small id='sUKOp'></small><noframes id='sUKOp'>

  • <tfoot id='sUKOp'></tfoot>
      <bdo id='sUKOp'></bdo><ul id='sUKOp'></ul>
    <i id='sUKOp'><tr id='sUKOp'><dt id='sUKOp'><q id='sUKOp'><span id='sUKOp'><b id='sUKOp'><form id='sUKOp'><ins id='sUKOp'></ins><ul id='sUKOp'></ul><sub id='sUKOp'></sub></form><legend id='sUKOp'></legend><bdo id='sUKOp'><pre id='sUKOp'><center id='sUKOp'></center></pre></bdo></b><th id='sUKOp'></th></span></q></dt></tr></i><div id='sUKOp'><tfoot id='sUKOp'></tfoot><dl id='sUKOp'><fieldset id='sUKOp'></fieldset></dl></div>

      <legend id='sUKOp'><style id='sUKOp'><dir id='sUKOp'><q id='sUKOp'></q></dir></style></legend>

      1. 我可以将 std::string 传递给 DLL 吗?

        时间:2023-07-19
          <bdo id='q9FZ3'></bdo><ul id='q9FZ3'></ul>

            <small id='q9FZ3'></small><noframes id='q9FZ3'>

              <legend id='q9FZ3'><style id='q9FZ3'><dir id='q9FZ3'><q id='q9FZ3'></q></dir></style></legend>
            1. <tfoot id='q9FZ3'></tfoot>
                <tbody id='q9FZ3'></tbody>

                • <i id='q9FZ3'><tr id='q9FZ3'><dt id='q9FZ3'><q id='q9FZ3'><span id='q9FZ3'><b id='q9FZ3'><form id='q9FZ3'><ins id='q9FZ3'></ins><ul id='q9FZ3'></ul><sub id='q9FZ3'></sub></form><legend id='q9FZ3'></legend><bdo id='q9FZ3'><pre id='q9FZ3'><center id='q9FZ3'></center></pre></bdo></b><th id='q9FZ3'></th></span></q></dt></tr></i><div id='q9FZ3'><tfoot id='q9FZ3'></tfoot><dl id='q9FZ3'><fieldset id='q9FZ3'></fieldset></dl></div>

                  本文介绍了我可以将 std::string 传递给 DLL 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我将一个代码片段分成一个 DLL,因为它会经常更新,这样它应该更容易部署.

                  I separated a code fragment into a DLL because it will be frequently updated and in this way it should be easier to deploy.

                  但是我对使用 DLL 可以做什么和不能做什么有疑问.

                  But I have questions about what I can do and what I cannot do with a DLL.

                  1. 我可以将 std:stringCString 传递给 DLL 吗?
                  2. 我可以将指针传递到带有 std::string 成员struct 并将其填充到 DLL 中吗?
                  3. DLL 能否返回一个指向分配在那里的结构的指针?它会有效吗?之后可以删除吗?
                  4. 什么应该更好地传递,std::String 还是 Cstring?
                  1. Can I pass a std:string or a CString to a DLL?
                  2. Can I pass a pointer to a struct with std::string members and fill it in a DLL?
                  3. Can a DLL return a pointer to a struct allocated there? Will it be valid? Can I delete it after?
                  4. What should better to pass, a std::String or a 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::stringCString).所有分配和对象创建都必须通过工厂函数完成.内存必须从分配它的模块中释放.代码和数据是分开的.头文件明确说明了每个导出函数的调用约定以及允许跨越模块边界的每个结构的打包.优点是可以完全独立地更新 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.

                  这篇关于我可以将 std::string 传递给 DLL 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:删除指向子类的指针是否调用基类析构函数? 下一篇:程序终止后动态分配的内存

                  相关文章

                  • <bdo id='4a6ha'></bdo><ul id='4a6ha'></ul>
                  <tfoot id='4a6ha'></tfoot>

                    1. <legend id='4a6ha'><style id='4a6ha'><dir id='4a6ha'><q id='4a6ha'></q></dir></style></legend>
                      <i id='4a6ha'><tr id='4a6ha'><dt id='4a6ha'><q id='4a6ha'><span id='4a6ha'><b id='4a6ha'><form id='4a6ha'><ins id='4a6ha'></ins><ul id='4a6ha'></ul><sub id='4a6ha'></sub></form><legend id='4a6ha'></legend><bdo id='4a6ha'><pre id='4a6ha'><center id='4a6ha'></center></pre></bdo></b><th id='4a6ha'></th></span></q></dt></tr></i><div id='4a6ha'><tfoot id='4a6ha'></tfoot><dl id='4a6ha'><fieldset id='4a6ha'></fieldset></dl></div>

                      <small id='4a6ha'></small><noframes id='4a6ha'>