I believe your error is right here
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern int SetParent(int hWndChild, int hWndNewParent);
It's expecting two arguments of type IntPtr
not int
and it returns an IntPtr
not an int
.
MSDN provides more information. See the user contributions towards the bottom for some good C# examples.
Keep in mind that an extern, when used with DllImport
, is a reference to unmanaged code. The method called SetParent()
in the user32.dll doesn't have a definition that accepts two int
s as parameters.
So that block should read:
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);