コード例 #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,
                                     SafeNativeMethods.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(SafeNativeMethods.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, SafeNativeMethods.TASKDIALOG_ELEMENTS element)
        {
            AssertCurrentlyShowing();

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