I’m having to convert from System.String (C#) into a PCTSTR which would be typed as _nullterminated const char*
So far I can’t find anything that can tell me exactly how to do this.
Plenty of examples to convert from System::String (C++/CLI), but I can’t find anything on System.String (C#)
I’m working in Visual Studio 2005.
When
PCTSTRis a typedef forconst char*, use Marshal.StringToHGlobalAnsi.When
PCTSTRis a typedef forconst wchar_t*, use Marshal.StringToHGlobalUni.In both cases, call Marshal.FreeHGlobal to free the memory when you’re done with it; despite your using C#, the memory allocation in question is unmanaged, so consequently is not eligible for garbage collection and will leak if you don’t clean it up properly.