예제 #1
0
        /// <summary>
        /// Allow lower integrity applications to send specified window messages
        /// in case we are elevated. Failure is non-fatal and on down-level
        /// platforms this call will result in a no-op.
        /// </summary>
        private void ChangeWindowMessageFilter(WindowMessage message, uint flag)
        {
            // Find the address of ChangeWindowMessageFilter in user32.dll.
            IntPtr user32Module = UnsafeNativeMethods.GetModuleHandle("user32.dll");

            // Get the address of the function. If this fails it means the OS
            // doesn't support this function, in which case we don't
            // need to do anything further.
            IntPtr functionAddress = UnsafeNativeMethods.GetProcAddressNoThrow(
                new HandleRef(null, user32Module),
                "ChangeWindowMessageFilter");

            if (functionAddress != IntPtr.Zero)
            {
                // Convert the function pointer into a callable delegate and then call it
                ChangeWindowMessageFilterNative function = Marshal.GetDelegateForFunctionPointer(
                    functionAddress,
                    typeof(ChangeWindowMessageFilterNative)) as ChangeWindowMessageFilterNative;

                // In order to call the function we need unmanaged code access,
                // because the function is native code.
                (new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)).Assert();
                try
                {
                    function(message, flag);
                }
                finally
                {
                    SecurityPermission.RevertAssert();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Allow lower integrity applications to send specified window messages
        /// in case we are elevated. Failure is non-fatal and on down-level
        /// platforms this call will result in a no-op.
        /// </summary>
        private void ChangeWindowMessageFilter(WindowMessage message, uint flag)
        {
            // Find the address of ChangeWindowMessageFilter in user32.dll.
            IntPtr user32Module = UnsafeNativeMethods.GetModuleHandle("user32.dll");

            // Get the address of the function. If this fails it means the OS
            // doesn't support this function, in which case we don't
            // need to do anything further.
            IntPtr functionAddress = UnsafeNativeMethods.GetProcAddressNoThrow(
                new HandleRef(null, user32Module),
                "ChangeWindowMessageFilter");

            if (functionAddress != IntPtr.Zero)
            {
                // Convert the function pointer into a callable delegate and then call it
                ChangeWindowMessageFilterNative function = Marshal.GetDelegateForFunctionPointer(
                    functionAddress,
                    typeof(ChangeWindowMessageFilterNative)) as ChangeWindowMessageFilterNative;

                function(message, flag);
            }
        }