Ok, That was the only situation I could thing of. Could this be releated to the GDI+ library? GDI+ architecture is not exactly managed code friendly...
I don't know exactly what are you at, but I managed to solve this on C# by creating the variable in the function 'caller' passing it as a parameter, and the same function caller 'frees' the variable inmediatly after the function call. That makes the unmanaged functioning of the variable transparent to managed code (in this case, the module user). I supose OnPain is a sort of event or 'event connector' on wxWidgets, so this could be doable. If I'm wrong, just forget it. :D
I don't know exactly what are you at, but I managed to solve this on C# by creating the variable in the function 'caller' passing it as a parameter, and the same function caller 'frees' the variable inmediatly after the function call. That makes the unmanaged functioning of the variable transparent to managed code (in this case, the module user). I supose OnPain is a sort of event or 'event connector' on wxWidgets, so this could be doable. If I'm wrong, just forget it. :D