开发者

Using CLI C++ dll with /MDd CRT in a native c++ exe with /MTd CRT

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜