Update the P / Invoke declaration of your external function as such:
[DllImport ( "MyDll.dll", CharSet = CharSet.Ansi, EntryPoint = "Func" )] [return : MarshalAs( UnmanagedType.LPStr )] string Func ( ... );
This way you do not have to do extra work after getting the pointer.
source share