private void SetText(TASKDIALOG_ELEMENTS tde, string text, bool relayout)
 {
     using (StringMarshaller sm = new StringMarshaller(text))
     {
         SendMessage(
             relayout ? TASKDIALOG_MESSAGES.TDM_SET_ELEMENT_TEXT : TASKDIALOG_MESSAGES.TDM_UPDATE_ELEMENT_TEXT,
             (int)tde,
             sm.Value.ToInt32());
     }
 }
        public void Show(IWin32Window dialogOwner, out int buttonResult, out int radioButtonResult, out bool verificationFlagResult)
        {
            config.hInstance  = IntPtr.Zero;
            config.hwndParent = (dialogOwner != null) ? dialogOwner.Handle : IntPtr.Zero;

            TaskDialogIcon mainIconToUse = mainIcon ?? TaskDialogIcon.None;

            config.hMainIcon = mainIconToUse.Value;
            SetFlag(TASKDIALOG_FLAGS.TDF_USE_HICON_MAIN, mainIconToUse.UseIcon);

            TaskDialogIcon footerIconToUse = footerIcon ?? TaskDialogIcon.None;

            config.hFooterIcon = footerIconToUse.Value;
            SetFlag(TASKDIALOG_FLAGS.TDF_USE_HICON_FOOTER, footerIconToUse.UseIcon);

            using (StructArrayMarshaller <TASKDIALOG_BUTTON> samButtons = MarshalButtons(buttons))
            {
                using (StructArrayMarshaller <TASKDIALOG_BUTTON> samRadioButtons = MarshalButtons(radioButtons))
                {
                    List <StringMarshaller> marshallers = new List <StringMarshaller>();
                    StringMarshaller        sm;

                    try
                    {
                        sm = new StringMarshaller(WindowTitle);
                        config.pszWindowTitle = sm.Value;
                        marshallers.Add(sm);

                        sm = new StringMarshaller(MainInstruction);
                        config.pszMainInstruction = sm.Value;
                        marshallers.Add(sm);

                        sm = new StringMarshaller(Content);
                        config.pszContent = sm.Value;
                        marshallers.Add(sm);

                        sm = new StringMarshaller(VerificationText);
                        config.pszVerificationText = sm.Value;
                        marshallers.Add(sm);

                        sm = new StringMarshaller(ExpandedInformation);
                        config.pszExpandedInformation = sm.Value;
                        marshallers.Add(sm);

                        sm = new StringMarshaller(ExpandedControlText);
                        config.pszExpandedControlText = sm.Value;
                        marshallers.Add(sm);

                        sm = new StringMarshaller(CollapsedControlText);
                        config.pszCollapsedControlText = sm.Value;
                        marshallers.Add(sm);

                        sm = new StringMarshaller(Footer);
                        config.pszFooter = sm.Value;
                        marshallers.Add(sm);

                        config.cButtons = (uint)buttons.Count;
                        config.pButtons = samButtons.Buffer;

                        config.cRadioButtons = (uint)radioButtons.Count;
                        config.pRadioButtons = samRadioButtons.Buffer;

                        int key = mTopmostTaskDialogMapKey++;
                        mRunningTaskDialogMap[key] = this;
                        config.lpCallbackData      = (IntPtr)key;

                        int verificationFlagResultInt;
                        int hr = TaskDialogNative.TaskDialogIndirect(
                            ref config,
                            out buttonResult,
                            out radioButtonResult,
                            out verificationFlagResultInt);
                        verificationFlagResult = verificationFlagResultInt != 0;

                        Marshal.ThrowExceptionForHR(hr);
                        mRunningTaskDialogMap.Remove(key);
                    }
                    finally
                    {
                        foreach (var marshaller in marshallers)
                        {
                            marshaller.Dispose();
                        }
                    }
                }
            }
        }