• MFC下VECTOR释放debug错误


    If your DLL and Exe use the static CRT, this won't work properly. Use the DLL CRT in both Exe and DLL. (/MD or /MDd)

     Unjedai wrote:

    Can I have the following method in a DLL and call it from a Client, like this?

    // DLL file

    void DllFunction (std::vector<int> &B)
    {
      B.push_back(1);
    }

     ----------------------

    // Client file

    void SomeFunction ()
    {
      std::vector<int> A;

      DllFunction(A);
    }

    When I try to do this I get a runtime error in _CrtIsValidHeapPointer (dbgheap.c) when SomeFunction returns.  I figured the problem is that the DLL allocates the memory and the Client is trying to free it and that's bad.

    So, what do people do when they want to pass an STL vector as a reference parameter to a DLL?  Cannot such a basic thing be done?

    I've made sure my runtime libraries are the same for the dll and the client (/MTd).

    参考此处得到解决
    项目属性->c/c++->code generation->runtime library 改为MDd;
    项目属性->general->use of mfc->use mfc in a shared dll
  • 相关阅读:
    常春藤之路,从幼儿园开始走起
    常青藤零距离
    web-service
    WebService到底是什么?
    How to add libraries to “External Libraries” in WebStorm/PhpStorm/Intellij
    浏览器核心说明
    万维网
    js和jquery获取span里面的值
    TPshop学习
    sphinx文档
  • 原文地址:https://www.cnblogs.com/mysunnyday/p/2129327.html
Copyright © 2020-2023  润新知