Re: URGENT: Local variables dissapear after unmanaged function call

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"Papa.Coen" <papa.coen@xxxxxxxxx> wrote in message
news:1182424110.527494.72550@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Right after I call a function in an external dll, some of my local
variables, not used in the call (!!!) in any way, are 'null' right
after the call.

(Pseudo)code

[Dllimport ...]
public static ... calc(...)

StringBuilder sB = new StringBuilder("hello");
String tmp = "I'm on my own";

calc(ref tmp);
// sB = null here!

What's happening here!?

Looks like a classic buffer overrun. Were you supposed to pass a reference
to a String tracking handle? Probably not. So the function took the space
you gave it, just big enough for a tracking handle, and wrote beyond that.




.