直接上代码,vs2005int _tmain(int argc, _TCHAR* argv[])
{ {
multimap<int,wstring> myResult;
myResult.insert(pair<int,wstring>(2,_T("Ddd")));
CopyResultMap(myResult); }//myResult析构,报错点
return 0;
}
dll中的CopyResultMap(myResult)函数extern "C" _declspec(dllexport) int CopyResultMap(multimap<int,wstring>& myResult)
{
int i=0;
myResult.insert(pair<int,wstring>(2,_T("Ddd")));//把这行代码去掉是可以的
return i;
}我的想法就在dll中插入map值,然后在main函数中用,但会报堆使用错误
有人说是dll和主函数使用的是不同的堆,所以主函数不能析构dll中insert的值,然后就内存泄露了,请问是这样不,有什么解决办法不

解决方案 »

  1.   

    如果只是让DLL内部调用insert的话
    你可以在主程序中实现
    typedef void Function(int, LPCTSTR);
    void Insert(int nKey, LPCTSTR lpszString)
    {
       myResult.insert(pair<int,wstring>(nKey, lpszString));
    }并将DLL函数参数改为Function* pFunction的函数指针,让DLL回调主函数的Insert函数
    extern "C" _declspec(dllexport) int CopyResultMap(Function* pFunction)
    {
        pFunction(2,_T("Ddd"));
        return 0;
    }
    时候将
      

  2.   

    这只是个示例程序,我精简了很多,我必须要在dll中insert,因为map的值是从dll中的一个全局变量copy过来的