Created
July 2, 2018 08:49
-
-
Save dogguts/66cd6b119a4d0a444cd34997fe4ce2d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static IntPtr StringToHGlobalUTF8(string s, out int length) | |
| { | |
| if (s == null) | |
| { | |
| length = 0; | |
| return IntPtr.Zero; | |
| } | |
| var bytes = System.Text.Encoding.UTF8.GetBytes(s); | |
| var ptr = Marshal.AllocHGlobal(bytes.Length + 1); | |
| Marshal.Copy(bytes, 0, ptr, bytes.Length); | |
| Marshal.WriteByte(ptr, bytes.Length, 0); | |
| length = bytes.Length; | |
| return ptr; | |
| } | |
| public static IntPtr StringToHGlobalUTF8(string s) | |
| { | |
| int temp; | |
| return StringToHGlobalUTF8(s, out temp); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment