/// <summary> /// Shows a text input dialog to the user. Maximum length of entered text is 10000 characters. /// </summary> /// <param name="title">Text in the dialogs title bar.</param> /// <param name="text">The initial text of dialog. Can be null for empty string.</param> /// <returns>True if successful or false on cancel.</returns> public static bool GetText(string title, ref string text) { IntPtr cstring = IntPtr.Zero; try { // According to manual 10240 characters maximum+2 extra for zero term safety etc. cstring = Marshal.AllocHGlobal(10242); int cnt = 0; if (text != null) { byte[] utfcode = Encoding.UTF8.GetBytes(text); if (utfcode.Length > 10240) { Array.Resize <byte>(ref utfcode, 10240); } cnt = utfcode.Length; Marshal.Copy(utfcode, 0, cstring, cnt); } Marshal.WriteByte(cstring, cnt, 0); if (NativeIUP.IupGetText(title, cstring) != 0) { text = IupHandle.UTF8ToStr(cstring); return(true); } return(false); } finally { if (cstring != IntPtr.Zero) { Marshal.FreeHGlobal(cstring); } } }
internal static string UTF8ToStr(IntPtr ptr) { //Just a shortcut! return(IupHandle.UTF8ToStr(ptr)); }