/// <summary>Allocates a new string on the unmanaged heap, and stores the pointer so we can free it later.</summary> /// <param name="text">The string to create.</param> /// <param name="element">The element.</param> /// <returns>The pointer for the new string.</returns> IntPtr MakeNewString(string text, TaskDialogElements element) { IntPtr newStringPtr = Marshal.StringToHGlobalUni(text); updatedStrings[(int)element] = newStringPtr; return(newStringPtr); }
/// <summary>Updates the text.</summary> /// <param name="text">The text to display.</param> /// <param name="element">The element where the text is displayed on.</param> void UpdateTextCore(string text, TaskDialogElements element) { AssertCurrentlyShowing(); FreeOldString(element); SendMessageHelper(TaskDialogMessages.SetElementText, (int)element, (long)MakeNewString(text, element)); }
/// <summary>Frees the old string.</summary> /// <param name="element">The element.</param> void FreeOldString(TaskDialogElements element) { var elementIndex = (int)element; if (updatedStrings[elementIndex] != IntPtr.Zero) { Marshal.FreeHGlobal(updatedStrings[elementIndex]); updatedStrings[elementIndex] = IntPtr.Zero; } }
/// <summary>Allocates a new string on the unmanaged heap, and stores the pointer so we can free it later.</summary> /// <param name="text">The string to create.</param> /// <param name="element">The element.</param> /// <returns>The pointer for the new string.</returns> IntPtr MakeNewString(string text, TaskDialogElements element) { IntPtr newStringPtr = Marshal.StringToHGlobalUni(text); updatedStrings[(int)element] = newStringPtr; return newStringPtr; }
private void CheckUpdateElementText(TaskDialogUpdateElements updateFlags, TaskDialogUpdateElements flagToCheck, TaskDialogElements element, string text) { if ((updateFlags & flagToCheck) == flagToCheck) { IntPtr strPtr = Marshal.StringToHGlobalUni(text); try { // Note: SetElementText will resize the dialog while UpdateElementText will not (which would // lead to clipped controls), so we use the former. SendTaskDialogMessage(TaskDialogMessages.SetElementText, (int)element, strPtr); } finally { // We can now free the memory because SendMessage does not return until the // message has been processed. Marshal.FreeHGlobal(strPtr); } } }