How to use VS2010 built dlls in VS2008

时光怂恿深爱的人放手 提交于 2019-12-11 07:49:57

问题


In my work we have VS2008. Some partners in the project I work, use VS2010 (can't use VS2008)

They have to build a dll based and I have to use that dll in my framework...

I managed to build the main app and link the dll's. the app starts, and objects from the VS2010 dll's are created, but the app crashes when i try to delete these objects...

Windows has triggered a breakpoint in app.exe. This may be due to a corruption of the heap, which indicates a bug in app.exe or any of the DLLs it has loaded.

Have you any ideas on how to fix this?


回答1:


Your co-workers' DLLs are linked against VS2010's runtime library. Your code is linked against VS2008's runtime library.

When you call some function from the VS2010 dll to allocate a new object, it will be allocated on that library's heap. When you call "delete" on that object, VS2008's runtime library will try to free it from its own heap. Since they're different, you get that error.

If you're going to mix runtimes like that, you need the VS2010 dll to expose free()-style functions (not just C++ destructors) for each type. There are other things you should be very careful with when mixing runtime libraries like that, such as using STL containers, or any sort of "copy-on-write" objects. In general, it's easier to avoid it.




回答2:


Object that was allocated in dll or in an exe should be deallocated in same place. You need to talk about that with your partners. For the goal may be used overloading of allocating and deallocating operators http://www.cprogramming.com/tutorial/operator_new.html



来源:https://stackoverflow.com/questions/6531401/how-to-use-vs2010-built-dlls-in-vs2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!