I have a native c++ exe using the /MTd runtime library. I cannot change this option as I dont have much control over the build of this exe. I need to call a CLI C++ dll in this exe which returns a class with STL vector member variables. At the return of the CLI C++ method, I get a heap corruption error. From my analysis, this happens because there are two different CRTs and the vectors deallocate method is running in the native开发者_开发技巧 CRT and bombs due to invalid address.
How do I return a vector from a CLI C++ dll which is compiled with a different CRT to run with my native exe?
Your assessment is correct -- allocations performed inside one CRT cannot be deallocated inside a different CRT. It's a simple rule, and there's no way around it.
You need to build both modules with the same runtime library settings, or you need to transfer only POD-types between module boundaries.
精彩评论