c# - P-invoke call fails if too much memory is assigned beforehand -


I got a call call for an unmanaged DLL which was unsuccessful in my WPF app but was a simple, Starter WPF App I tried to figure out what was the problem but eventually came to the conclusion that if I give a lot of memory before calling, the call fails. I had two different blocks of code, both of which would be successful in themselves, but they could fail if they failed. (They had no idea what to do with P-Inoke by calling them.)

What kind of issues will be the cause of such issue in unmanaged libraries? I thought the managed and uncompressed pile should have been automatically separated.

As an accident, I can tell that a dynamic load is happening in secondary DLL, is there something to do with it?

The uncompressed code is prone to corrupt the heap. The ill effects of that corruption are very unpredictable, it depends on what happens after that corrupted memory, it is not uncommon that if corruption is not in any important place, then nothing bad happens. Changing the memory allocation pattern of your program can change that result.

All of you really know right now that unmanaged code can not be trusted. Doing something about it, is strictly tough, especially from managed host programs. Unless you start writing unit tests for that unmanaged code, using unmanaged code to use it, and detect a reputable bomb that you can deal with an unmanaged debugger.


Comments