Skip to content

Commit

Permalink
Check for the return value of native SetParent calls in Control… (#2262)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxinyanc authored and RussKie committed Dec 4, 2019
1 parent f5080ee commit 4b4f8cf
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/Common/src/Interop/User32/Interop.SetParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static partial class Interop
{
internal static partial class User32
{
[DllImport(Libraries.User32, ExactSpelling = true)]
[DllImport(Libraries.User32, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndChildNewParent);

public static IntPtr SetParent(IntPtr hWndChild, HandleRef hWndChildNewParent)
Expand Down
5 changes: 4 additions & 1 deletion src/System.Windows.Forms/src/Resources/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4513,7 +4513,7 @@ Stack trace where the illegal operation occurred was:
</data>
<data name="PrintPreviewDialog_PrintPreview" xml:space="preserve">
<value>Print preview</value>
</data>
</data>
<data name="PrintPreviewDocumentDescr" xml:space="preserve">
<value>PrintDocument to be previewed.</value>
</data>
Expand Down Expand Up @@ -6653,4 +6653,7 @@ Stack trace where the illegal operation occurred was:
<data name="DefaultUpDownButtonsAccessibleName" xml:space="preserve">
<value>UpDown</value>
</data>
<data name="Win32SetParentFailed" xml:space="preserve">
<value>Failed to set Win32 parent window of the Control.</value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,10 @@ internal unsafe void InPlaceActivate(Ole32.OLEIVERB verb)
// If it doesn't, that means that the host
// won't reflect messages back to us.
HWNDParent = hwndParent;
User32.SetParent(new HandleRef(_control, _control.Handle), hwndParent);
if (User32.SetParent(new HandleRef(_control, _control.Handle), hwndParent) == IntPtr.Zero)
{
throw new Win32Exception(Marshal.GetLastWin32Error(), SR.Win32SetParentFailed);
}

// Now create our handle if it hasn't already been done.
_control.CreateControl();
Expand Down
Loading

0 comments on commit 4b4f8cf

Please sign in to comment.