Yes, not a problem. This is actually somewhat documented , but hard to find. MSDN docs for C ++ libraries are small. It returns an internal pointer that is not yet suitable for conversion to const wchar_t *. You must attach a pointer so that the garbage collector cannot move the string. Use pin_ptr <> for this.
You can use Marshal :: StringToHGlobalUni () to create a copy of the string. Use this instead if wchar_t * should remain valid for a long period of time. Extending objects for too long is not very useful for the garbage collector.
source
share