问题从一个c ++ dll重新调试一个向量到另一个c ++ exe [英] Problem retuning a vector from a c++ dll to another c++ exe

查看:240
本文介绍了问题从一个c ++ dll重新调试一个向量到另一个c ++ exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在dll A.dll中有一个函数foo(),其定义如下

I have a function foo() in dll A.dll, whose definition is as follows

vector<CustomObject> foo()  
{   
      vector<CustomObject> customObjectCollection;

   //code which populates customObjectCollection goes here

return customObjectCollection;   
}



我指的是这个方法向量foo()dll A from exe B

I am referring this method vector foo() of dll A from exe B

当我从B调用函数foo时,得到一个未处理的异常,表示

When i make a call to the function foo from B, I get an unhandled exception which says


未处理的异常在
0x10487b3f(msvcp90d.dll)在B.exe
0xC0000005:访问冲突,
写入位置0xfdfdfdfd。

"unhandled exception at 0x10487b3f(msvcp90d.dll) in B.exe" 0xC0000005: Access violation while writing to the location 0xfdfdfdfd".

注意:类型CustomObject不实现复制构造函数

Note:type CustomObject does not implement copy constructor

当我试图通过附加B. exe到A.dll,我发现里面的方法向量foo(),向量填充没有任何问题,但是当控制返回到B.exe的向量阀不会被复制!!!

When i tried to debug by attaching B.exe to A.dll, I found that inside method vector foo(), the vector gets populated without any problem but when the control returns to B.exe the valves in vector doesnot get copied !!!

另外,如果方法foo通过引用返回向量,异常不会发生,并且B.exe接收一个空的vetor。

Also, if method foo returns vector by reference , exception doesnot occur and B.exe receives an empty vetor.

什么是问题?是因为我没有为CustomObject实现复制构造函数。

what is the issue ?? Is it happening as I have not implemented copy constructor for CustomObject.

任何帮助是非常感谢
(抱歉没有正确表达问题)

Any help is greatly appreciated (Apologies for not articulating the question properly)

感谢

jeel

Thanks
jeel

推荐答案

这是一个典型的症状的不匹配运行时库。您必须确保EXE和DLL都链接到动态C ++库(DLL版本)。

This is a classic symptom of mismatched runtime libraries. You have to make sure that both the EXE and the DLL are linked to the dynamic C++ library (DLL version).

如果一个(或两个)链接到静态C ++运行时(LIB版本),你会得到内存违反,因为将有两个运行时库的实例具有不同的地址空间。

If one (or both) are linked with the static C++ runtime (LIB version), you'll get memory violations since there will be two instances of the runtime library with different address spaces.

这篇关于问题从一个c ++ dll重新调试一个向量到另一个c ++ exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆