internal static int GetWindowLong(HandleRef hWnd, int nIndex)
        {
            var iResult = 0;
            var result  = IntPtr.Zero;
            var error   = 0;

            if (IntPtr.Size == 4)
            {
                // use GetWindowLong
                iResult = NativeMethodsSetLastError.GetWindowLong(hWnd, nIndex);
                error   = Marshal.GetLastWin32Error();
                result  = new IntPtr(iResult);
            }
            else
            {
                // use GetWindowLongPtr
                result  = NativeMethodsSetLastError.GetWindowLongPtr(hWnd, nIndex);
                error   = Marshal.GetLastWin32Error();
                iResult = NativeMethods.IntPtrToInt32(result);
            }

            if (result == IntPtr.Zero && error != 0)
            {
                Debug.WriteLine("GetWindowLong failed.  Error = " + error);
            }

            return(iResult);
        }
        public static IntPtr GetParent(HandleRef hWnd)
        {
            var parent         = NativeMethodsSetLastError.GetParent(hWnd);
            var lastWin32Error = Marshal.GetLastWin32Error();

            if (parent == IntPtr.Zero && lastWin32Error != 0)
            {
                throw new Win32Exception(lastWin32Error);
            }
            return(parent);
        }
        /// <summary>
        ///     Criticals the set window long.
        /// </summary>
        /// <param name="hWnd">The h WND.</param>
        /// <param name="nIndex">Index of the n.</param>
        /// <param name="dwNewLong">The dw new long.</param>
        /// <returns>IntPtr.</returns>
        internal static IntPtr CriticalSetWindowLong(HandleRef hWnd, int nIndex, IntPtr dwNewLong)
        {
            var result = IntPtr.Zero;

            if (IntPtr.Size == 4)
            {
                // use SetWindowLong
                var tempResult =
                    NativeMethodsSetLastError.SetWindowLong(hWnd, nIndex, NativeMethods.IntPtrToInt32(dwNewLong));
                result = new IntPtr(tempResult);
            }
            else
            {
                // use SetWindowLongPtr
                result = NativeMethodsSetLastError.SetWindowLongPtr(hWnd, nIndex, dwNewLong);
            }

            return(result);
        }