Exemple #1
0
 public static void SetTimer(HandleRef hWnd, int nIDEvent, int uElapse)
 {
     if (SafeNativeMethodsPrivate.SetTimer(hWnd, nIDEvent, uElapse, null) == IntPtr.Zero)
     {
         throw new Win32Exception();
     }
 }
 public static void QueryPerformanceFrequency(out long lpFrequency)
 {
     if (!SafeNativeMethodsPrivate.QueryPerformanceFrequency(out lpFrequency))
     {
         throw new Win32Exception(Marshal.GetLastWin32Error());
     }
 }
Exemple #3
0
 internal static void GetWindowRect(HandleRef hWnd, [In, Out] ref NativeMethods.RECT rect)
 {
     if (!SafeNativeMethodsPrivate.IntGetWindowRect(hWnd, ref rect))
     {
         throw new Win32Exception();
     }
 }
Exemple #4
0
 internal static void GetMonitorInfo(HandleRef hmonitor, [In, Out] NativeMethods.MONITORINFOEX info)
 {
     if (SafeNativeMethodsPrivate.IntGetMonitorInfo(hmonitor, info) == false)
     {
         throw new Win32Exception();
     }
 }
Exemple #5
0
        // not used by compiler - don't include.

        public static void ScreenToClient(HandleRef hWnd, [In, Out] NativeMethods.POINT pt)
        {
            if (SafeNativeMethodsPrivate.IntScreenToClient(hWnd, pt) == 0)
            {
                throw new Win32Exception();
            }
        }
        // Note: this returns true or false for success.  We still don't have an overload
        // that returns the timer ID.
        public static bool TrySetTimer(HandleRef hWnd, int nIDEvent, int uElapse)
        {
            if (SafeNativeMethodsPrivate.TrySetTimer(hWnd, nIDEvent, uElapse, null) == IntPtr.Zero)
            {
                return(false);
            }

            return(true);
        }
Exemple #7
0
        public static int GetCaretBlinkTime()
        {
            // To be consistent with our other PInvoke wrappers
            // we should "throw" a Win32Exception on error here.
            // But we don't want to introduce new "throws" w/o
            // time to follow up on any new problems that causes.

            return(SafeNativeMethodsPrivate.GetCaretBlinkTime());
        }
        public static NativeMethods.CursorHandle LoadCursor(HandleRef hInst, IntPtr iconId)
        {
            NativeMethods.CursorHandle cursorHandle = SafeNativeMethodsPrivate.LoadCursor(hInst, iconId);
            if (cursorHandle == null || cursorHandle.IsInvalid)
            {
                throw new Win32Exception();
            }

            return(cursorHandle);
        }
        internal static bool AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle)
        {
            var returnValue = SafeNativeMethodsPrivate.IntAdjustWindowRectEx(ref lpRect, dwStyle, bMenu, dwExStyle);

            if (returnValue == false)
            {
                throw new Win32Exception();
            }
            return(returnValue);
        }
        internal static bool ReleaseCapture()
        {
            var returnValue = SafeNativeMethodsPrivate.IntReleaseCapture();

            if (returnValue == false)
            {
                throw new Win32Exception();
            }
            return(returnValue);
        }
        public static bool TrackMouseEvent(NativeMethods.TRACKMOUSEEVENT tme)
        {
            bool retVal   = SafeNativeMethodsPrivate.TrackMouseEvent(tme);
            int  win32Err = Marshal.GetLastWin32Error(); // Dance around FxCop

            if (!retVal && win32Err != 0)
            {
                throw new System.ComponentModel.Win32Exception(win32Err);
            }
            return(retVal);
        }
Exemple #12
0
        /// <summary>
        /// Retrieves the dots per inch (dpi) awareness of the specified process
        /// </summary>
        /// <param name="hProcess">[in]
        /// Handle of the process that is being queried. If this parameter
        /// is null, the current process is queried.
        /// </param>
        /// <returns>The <see cref="NativeMethods.PROCESS_DPI_AWARENESS"/> of the specified process</returns>
        /// <exception cref="ArgumentException">The handle <paramref name="hProcess"/> is not valid</exception>
        /// <exception cref="UnauthorizedAccessException">The application does not have sufficient priviliges</exception>
        /// <exception cref="COMException">
        /// The call to Win32 GetProcessDpiAwareness function failed with some other error.
        /// The error code in the exception object will contain the corresponding HRESULT
        /// </exception>
        /// <remarks>
        ///     - See remarks for <see cref="SafeNativeMethodsPrivate.GetProcessDpiAwareness(HandleRef, out IntPtr)"/>
        ///     - Minimum supported client: Windows 8.1
        /// </remarks>
        internal static NativeMethods.PROCESS_DPI_AWARENESS GetProcessDpiAwareness(HandleRef hProcess)
        {
            var ptrProcessDpiAwareness = IntPtr.Zero;
            var hr = (int)SafeNativeMethodsPrivate.GetProcessDpiAwareness(hProcess, out ptrProcessDpiAwareness);

            if (hr != NativeMethods.S_OK)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            return((NativeMethods.PROCESS_DPI_AWARENESS)NativeMethods.IntPtrToInt32(ptrProcessDpiAwareness));
        }
Exemple #13
0
        public static bool GetStringTypeEx(uint locale, uint infoType, char[] sourceString, int count,
                                           UInt16[] charTypes)
        {
            bool win32Return = SafeNativeMethodsPrivate.GetStringTypeEx(locale, infoType, sourceString, count, charTypes);
            int  win32Error  = Marshal.GetLastWin32Error();

            if (!win32Return)
            {
                throw new Win32Exception(win32Error);
            }

            return(win32Return);
        }
        /// <summary>
        /// Returns the ID of the session under which the current process is running
        /// </summary>
        /// <returns>
        /// The session id upon success, null on failure
        /// </returns>
        public static int?GetCurrentSessionId()
        {
            int?result = null;

            int sessionId;

            if (SafeNativeMethodsPrivate.ProcessIdToSessionId(
                    GetCurrentProcessId(), out sessionId))
            {
                result = sessionId;
            }

            return(result);
        }
Exemple #15
0
 /// <summary>
 /// Calculates the required size of the window rectangle, based on the desired size of the
 /// client rectangle and the provided DPI. This window rectangle can then be passed to the CreateWindowEx
 /// function to create a window with a client area of the desired size.
 /// </summary>
 /// <param name="lpRect">
 /// A pointer to a RECT structure that contains the coordinates of the top-left and bottom-right
 /// corners of the desired client area. When the function returns, the structure contains the coordinates
 /// of the top-left and bottom-right corners of the window to accommodate the desired client area.
 /// </param>
 /// <param name="dwStyle">
 /// The Window Style of the window whose required size is to be calculated. Note that
 /// you cannot specify the WS_OVERLAPPED style.
 /// </param>
 /// <param name="bMenu">Indicates whether the window has a menu.</param>
 /// <param name="dwExStyle">The Extended Window Style of the window whose required size is to be calculated.</param>
 /// <param name="dpi">The DPI to use for scaling.</param>
 /// <returns>
 /// If the function succeeds, the return value is true.
 /// If the function fails, the return value is false.
 /// To get extended error information, call GetLastError
 /// </returns>
 /// <remarks>
 /// Minimum supported client: Windows 10, version 1607 (RS1)
 /// </remarks>
 internal static bool AdjustWindowRectExForDpi(
     ref NativeMethods.RECT lpRect,
     int dwStyle,
     bool bMenu,
     int dwExStyle,
     int dpi)
 {
     return
         (SafeNativeMethodsPrivate.AdjustWindowRectExForDpi(
              ref lpRect,
              dwStyle,
              bMenu,
              dwExStyle,
              dpi));
 }
        /// <summary>
        /// Identifies whether the given workstation session ID has a WTSConnectState value
        /// of WTSActive, or not.
        /// </summary>
        /// <param name="SessionId">
        /// The ID of the workstation session to query. If this is null,
        /// then this will default to WTS_CURRENT_SESSION. Note that the ID of the
        /// current session will not be queried explicitly.
        /// </param>
        /// <param name="defaultResult">
        /// The default result to return if this method is unable to identify the connection
        /// state of the given session ID.
        /// </param>
        /// <returns>
        /// True if the connection state for <paramref name="SessionId"/> is WTSActive;
        /// false otherwise
        /// <paramref name="defaultResult"/> is returned if WTSQuerySessionInformation
        /// fails.
        /// </returns>
        public static bool IsCurrentSessionConnectStateWTSActive(int?SessionId = null, bool defaultResult = true)
        {
            IntPtr buffer = IntPtr.Zero;
            int    bytesReturned;

            int  sessionId = SessionId.HasValue ? SessionId.Value : NativeMethods.WTS_CURRENT_SESSION;
            bool currentSessionConnectState = defaultResult;

            try
            {
                if (SafeNativeMethodsPrivate.WTSQuerySessionInformation(
                        NativeMethods.WTS_CURRENT_SERVER_HANDLE,
                        sessionId,
                        NativeMethods.WTS_INFO_CLASS.WTSConnectState,
                        out buffer, out bytesReturned) && (bytesReturned >= sizeof(int)))
                {
                    var data = Marshal.ReadInt32(buffer);
                    if (Enum.IsDefined(typeof(NativeMethods.WTS_CONNECTSTATE_CLASS), data))
                    {
                        var connectState = (NativeMethods.WTS_CONNECTSTATE_CLASS)data;
                        currentSessionConnectState = (connectState == NativeMethods.WTS_CONNECTSTATE_CLASS.WTSActive);
                    }
                }
            }
            finally
            {
                try
                {
                    if (buffer != IntPtr.Zero)
                    {
                        SafeNativeMethodsPrivate.WTSFreeMemory(buffer);
                    }
                }
                catch (Exception e) when(e is Win32Exception || e is SEHException)
                {
                    // We will do nothing and return defaultResult
                    //
                    // Note that we don't want to catch and ignore SystemException types
                    // like AV, OOM etc.
                }
            }

            return(currentSessionConnectState);
        }
 public static bool IsWindowUnicode(HandleRef hWnd)
 {
     return(SafeNativeMethodsPrivate.IsWindowUnicode(hWnd));
 }
 public static bool KillTimer(HandleRef hwnd, int idEvent)
 {
     return(SafeNativeMethodsPrivate.KillTimer(hwnd, idEvent));
 }
 public static bool IsWindowEnabled(HandleRef hWnd)
 {
     return(SafeNativeMethodsPrivate.IsWindowEnabled(hWnd));
 }
 public static int GetDoubleClickTime()
 {
     return(SafeNativeMethodsPrivate.GetDoubleClickTime());
 }
 public static int ShowCursor(bool show)
 {
     return(SafeNativeMethodsPrivate.ShowCursor(show));
 }
 public static IntPtr ActivateKeyboardLayout(HandleRef hkl, int uFlags)
 {
     return(SafeNativeMethodsPrivate.ActivateKeyboardLayout(hkl, uFlags));
 }
 public static IntPtr GetKeyboardLayout(int dwLayout)
 {
     return(SafeNativeMethodsPrivate.GetKeyboardLayout(dwLayout));
 }
Exemple #24
0
 internal static int GetInputState()
 {
     return(SafeNativeMethodsPrivate.GetInputState());
 }
 public static IntPtr GetCapture()
 {
     return(SafeNativeMethodsPrivate.GetCapture());
 }
 public static int GetCurrentProcessId()
 {
     return(SafeNativeMethodsPrivate.GetCurrentProcessId());
 }
 public static int GetCurrentThreadId()
 {
     return(SafeNativeMethodsPrivate.GetCurrentThreadId());
 }
Exemple #28
0
 internal static bool InSendMessage()
 {
     return(SafeNativeMethodsPrivate.InSendMessage());
 }
 public static int GetMessagePos()
 {
     return(SafeNativeMethodsPrivate.GetMessagePos());
 }
Exemple #30
0
 public static int GetQueueStatus(uint flags)
 {
     return(SafeNativeMethodsPrivate.GetQueueStatus(flags));
 }