Пример #1
0
        // Allocates a new string on the unmanaged heap,
        // and stores the pointer so we can free it later.

        private IntPtr MakeNewString(string s,
                                     TaskDialogNativeMethods.TASKDIALOG_ELEMENTS element)
        {
            IntPtr newStringPtr = Marshal.StringToHGlobalUni(s);

            updatedStrings[(int)element] = newStringPtr;
            return(newStringPtr);
        }
Пример #2
0
        // Checks to see if the given element already has an
        // updated string, and if so,
        // frees it. This is done in preparation for a call to
        // MakeNewString(), to prevent
        // leaks from multiple updates calls on the same element
        // within a single native dialog lifetime.

        private void FreeOldString(TaskDialogNativeMethods.TASKDIALOG_ELEMENTS element)
        {
            int elementIndex = (int)element;

            if (updatedStrings[elementIndex] != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(updatedStrings[elementIndex]);
                updatedStrings[elementIndex] = IntPtr.Zero;
            }
        }
Пример #3
0
        private void UpdateTextCore(string s, TaskDialogNativeMethods.TASKDIALOG_ELEMENTS element)
        {
            AssertCurrentlyShowing();

            FreeOldString(element);
            SendMessageHelper(
                TaskDialogNativeMethods.TASKDIALOG_MESSAGES.TDM_SET_ELEMENT_TEXT,
                (int)element,
                (long)MakeNewString(s, element));
        }