/// <summary>
        /// Make sure we load penimc.dll from WPF's installed location to avoid two instances of it.
        /// </summary>
        static UnsafeNativeMethods()
        {
            // Register PenIMC for SxS COM for the lifetime of the process. No need to store the
            // cookie; PenIMC's ActivationContext will never be removed from the ActivationContext
            // stack.
            //
            // RegisterDllForSxSCOM returns a non-zero ActivationContextCookie if SxS registration
            // succeeds, or IntPtr.Zero if SxS registration fails.
            if (IntPtr.Zero == RegisterDllForSxSCOM())
            {
                throw new InvalidOperationException(SR.Get(SRID.PenImcSxSRegistrationFailed, ExternDll.Penimc));
            }

            // Ensure PenIMC loaded from the correct location.
            var uncheckedDlls = WpfDllVerifier.VerifyWpfDllSet(ExternDll.Penimc);

            if (uncheckedDlls.Contains(ExternDll.Penimc))
            {
                throw new DllNotFoundException(SR.Get(SRID.PenImcDllVerificationFailed, ExternDll.Penimc));
            }
        }
Exemple #2
0
        /// <summary>
        /// Make sure we load penimc.dll from WPF's installed location to avoid two instances of it.
        ///
        /// Add an activation context to the thread's stack to ensure the registration-free COM objects
        /// are available.
        /// </summary>
        /// <remarks>
        /// PenIMC COM objects are only directly used (functions called on their interfaces) from inside the
        /// PenThread.  As such, the PenThreads need to create the activation context.  The various Dispatcher
        /// threads need not do so as they merely pass the RCWs around in manged objects and will only use
        /// them via operations queued on their associated PenThread.
        /// </remarks>
        internal static void EnsurePenImcClassesActivated()
        {
            if (_pimcActCtxCookie == IntPtr.Zero)
            {
                // Register PenIMC for SxS COM for the lifetime of the thread.
                //
                // RegisterDllForSxSCOM returns a non-zero ActivationContextCookie if SxS registration
                // succeeds, or IntPtr.Zero if SxS registration fails.
                if ((_pimcActCtxCookie = RegisterDllForSxSCOM()) == IntPtr.Zero)
                {
                    throw new InvalidOperationException(SR.Get(SRID.PenImcSxSRegistrationFailed, ExternDll.Penimc));
                }

                // Ensure PenIMC loaded from the correct location.
                var uncheckedDlls = WpfDllVerifier.VerifyWpfDllSet(ExternDll.Penimc);

                if (uncheckedDlls.Contains(ExternDll.Penimc))
                {
                    throw new DllNotFoundException(SR.Get(SRID.PenImcDllVerificationFailed, ExternDll.Penimc));
                }
            }
        }
        //+---------------------------------------------------------------------
        //
        //  Internal Methods
        //
        //----------------------------------------------------------------------

        #region Internal Methods

        /// <summary>
        /// Sets the owner MediaContext and creates the notification window.
        /// </summary>
        internal MediaContextNotificationWindow(MediaContext ownerMediaContext)
        {
            // Remember the pointer to the owner MediaContext that we'll forward the broadcasts to.
            _ownerMediaContext = ownerMediaContext;

            // Create a top-level, invisible window so we can get the WM_DWMCOMPOSITIONCHANGED
            // and other DWM notifications that are broadcasted to top-level windows only.
            HwndWrapper hwndNotification;

            hwndNotification = new HwndWrapper(0, NativeMethods.WS_POPUP, 0, 0, 0, 0, 0, "MediaContextNotificationWindow", IntPtr.Zero, null);

            _hwndNotificationHook = new HwndWrapperHook(MessageFilter);

            _hwndNotification = new SecurityCriticalDataClass <HwndWrapper>(hwndNotification);
            _hwndNotification.Value.AddHook(_hwndNotificationHook);

            _isDisposed = false;

            //
            // On Vista, we need to know when the Magnifier goes on and off
            // in order to switch to and from software rendering because the
            // Vista Magnifier cannot magnify D3D content. To receive the
            // window message informing us of this, we must tell the DWM
            // we are MIL content.
            //
            // The Win7 Magnifier can magnify D3D content so it's not an
            // issue there. In fact, Win7 doesn't even send the WM.
            //
            // If the DWM is not running, this call will result in NoOp.
            //

            ChangeWindowMessageFilter(s_dwmRedirectionEnvironmentChanged, 1 /* MSGFLT_ADD */);
            MS.Internal.HRESULT.Check(MilContent_AttachToHwnd(_hwndNotification.Value.Handle));

            WpfDllVerifier.VerifyWpfDllSet();
        }