开发者

Calling malloc() from unmanaged DLL called within managed DLL generates access violation

开发者 https://www.devze.com 2023-03-16 13:59 出处:网络
I have a suite of tests written in C++/CLI that call into a native DLL in order to remotely test a W开发者_JS百科indows CE device.At two points during the test setup process, memory on the native heap

I have a suite of tests written in C++/CLI that call into a native DLL in order to remotely test a W开发者_JS百科indows CE device. At two points during the test setup process, memory on the native heap is allocated--once for 512 bytes, the other for 572 bytes. In both instances, malloc() eventually called HeapAlloc() using the CRT heap. The handle to the CRT heap did not change between calls. The call that was meant to allocate 572 bytes fails with exception 0xc0000005 (I can try to provide code examples if need be, but will have to figure out what examples are generic enough not to break NDA).


It looks like what finally solved the problem was not using the C Runtime heap, but using either GetProcessHeap() or a local heap to do the allocations.


Consider using a debugging malloc. Here's an article about using DevStudio debug mode in order to substitute special debugging versions of malloc and free.

0

精彩评论

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

关注公众号