How to use VS2010 built dlls in VS2008

2019-08-03 06:18发布

问题:

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