The biggest problem to consider when using a DLL compiled with a different C++ compiler than the calling EXE is memory allocation and object lifetime.
I'm assuming that you can get past the name mangling (and calling convention), which isn't difficult if you use a compiler with compatible mangling (I think VC6 is broadly compatible with VS2008), or if you use extern "C".
Where you'll run into problems is when you allocate something using new
(or malloc
) from the DLL, and then you return this to the caller. The caller's delete
(or free
) will attempt to free the object from a different heap. This will go horribly wrong.
You can either do a COM-style IFoo::Release
thing, or a MyDllFree()
thing. Both of these, because they call back into the DLL, will use the correct implementation of delete
(or free()
), so they'll delete the correct object.
Or, you can make sure that you use LocalAlloc
(for example), so that the EXE and the DLL are using the same heap.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…