October 20, 2011

gcroot and pin_ptr

Reference managed type members in an unmanaged class by using the "gcroot<>" template. This provides a wrapper around the GCHandle class.
Look at this msdn explanantion
Also there is this article on codeproject

gcroot str;
str = gcnew String("hello");

Pinning in C++/CLI. Do this using the pin_ptr keyword. This prevents the managed object from being moved around in memory by the garbage collector