zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:

    (luogu)[模板]最长公共子序列
    表达式的值
    邮票面值设计
    尼克的任务
    HISTOGRA
    消防局的设立
    青蛙的约会
    产生数
    奇怪的电梯
  • 原文地址:https://www.cnblogs.com/mysunnyday/p/2129327.html
Copyright © 2011-2022 走看看