我在dll的一个接口函数中用new分配了一块内存区域,我的另一个程序调这个dll的函数,函数执行完要返回这块内存给调用程序,并且要求在dll中分配这块内存,调试时系统报错(1.exe中的 0x0215240f (1.dll) 处未处理的异常: 0xC0000005: 读取位置 0x00000022 时发生访问冲突 。)为什么啊,我该怎么解决。

解决方案 »

  1.   

    函数执行完要返回这块内存给调用程序,并且要求在dll中分配这块内存
    ==
    请贴出你的函数接口以及内存是如何分配的,外部调用时是如何传递参数的。
      

  2.   

    感觉在 DLL中new内存而不释放,肯定要出问题。是不是可以改为在调用程序里面分配内存,由调用程序管理内存。
    要在 DLL中的函数中分配这个内存,你在函数退出之后,要用 DLL释放这一块内存是很麻烦的。要不将这个内存指针做成DLL的全局的,在 DLL退出的时候,清理掉。
      

  3.   

    我跟到dll里去看过是new的时候出错了
    extern "C" __declspec(dllexport) unsigned char* abc(  unsigned char* pData, long& nDataBytes )
    {
    unsigned char* pRetData = new unsigned char[nDataSize];//这里出错         ...... return pRetData;
    }
      

  4.   

    我跟到dll里去看过是new的时候出错了
    extern "C" __declspec(dllexport) unsigned char* abc(  unsigned char* pData, long& nDataBytes )
    {
    unsigned char* pRetData = new unsigned char[nDataBytes ];//这里出错         ...... return pRetData;
    }
      

  5.   

    nDataBytes是多少?new操作错误,无法分配空间?
      

  6.   

    unsigned char* pRetData = (unsigned char*)new unsigned char[nDataSize];
    对,看看nDataSize的值,不能小于1