I have a function defined a local variable typed in CStringW, is it safe to return this object to the caller by value, not by reference?
Yes, it should be ok. CString
internally uses a buffer with reference counting and does copy-on-write, so that when you create a copy of CString
and then destroy the original object, everything should "just work".