internal SafeProcessHandle(NativeMethods.HWND hwnd) : base(true)
        {
            int processId;

            // Get process id...
            // GetWindowThreadProcessId does use SetLastError().  So a call to GetLastError() would be meanless.
            // Disabling the PreSharp warning.
#pragma warning suppress 6523
            if (SafeNativeMethods.GetWindowThreadProcessId(hwnd, out processId) == 0)
            {
                throw new ElementNotAvailableException();
            }

            SetHandle(Misc.OpenProcess(UnsafeNativeMethods.PROCESS_QUERY_INFORMATION | UnsafeNativeMethods.PROCESS_VM_READ, false, processId, hwnd));
        }