I need to interact with a native third-party library I don't have the source code of. I get a heap corruption from just a simple thing like this:
void MyInterop::DoNastyStuff(String^ foo) {
ThirdParty::NativeThing x = ThirdParty::NativeThing(msclr::interop::marshal_as<std::wstring>(foo));
x.doSomething(); // fine
System::Console::WriteLine("foo"); // fine
} // boom
The heap corruption occurrs as soon as the method is left (this means, I can put as much code after the x.doSomething()
as I want and everything runs fine).
When I create the third-party stuff on the heap, I get the heap corruption when using the delete
command
void MyInterop::DoNastyStuffOnHeap(String^ foo) {
ThirdParty::NativeThing* x = new ThirdParty::NativeThing(msclr::interop::marshal_as<std::wstring>(foo));
x->doSomething(); // fine
delete x; // boom
System::Console::WriteLine("foo"); // fine after clicking Ignore in the dialog that pops up from VS
}
I already filed a bug report to the third party that provide me the DLL, but is there any workaround in the meantime for this?