How can I convert an unmanaged IntPtr type to a c# string?

前端 未结 2 1456
广开言路
广开言路 2020-12-11 00:37

I\'m new to C# (from a native C++ background) and I\'m trying to write a little UI to print windows broadcast messages among other things. I\'ve overridden the default WndP

2条回答
  •  一生所求
    2020-12-11 01:05

    The above answer was great and it nearly solved the same issue for me but... I got what looks like Chinese characters back from the method (潆湵⁤瑡氠慥瑳漠敮爠灥慥整⁤浩条⁥慮敭›䌢⸢). What I had to do was use the Marshal.PtrToStringAnsi(IntPtr) method as described here: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.ptrtostringansi.aspx and here: http://answers.unity3d.com/questions/555441/unitys-simplest-plugin-print-does-not-work.html.

    Once I made the change, my String was in English once more. Not sure why that was happening, but there ya go!

提交回复
热议问题