Ejemplo n.º 1
0
        private void RegisterCallback(IBindCtx pbc, Uri monikerUri)
        {
            var callback = new BindStatusCallback(monikerUri, owner);
            IBindStatusCallback previous;
            IntPtr result = RegisterBindStatusCallback(pbc, callback, out previous, 0);

            // The call to RegisterBindStatusCallback will fail if the default calback "_BSCB_Holder_" is registered.
            // Remove it and try again. (This trick has been taken from
            // <http://www.codeproject.com/KB/atl/vbmhwb.aspx?fid=180355&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2211230>.)
            if (HResults.Equals(result, HResults.E_FAIL) && previous != null)
            {
                pbc.RevokeObjectParam("_BSCB_Holder_");
                callback.PreviousCallback = previous;
                result = RegisterBindStatusCallback(pbc, callback, out previous, 0);
            }

            if (!HResults.Equals(result, HResults.S_OK))
            {
                throw new InvalidOperationException("Could not register custom bind status callback.");
            }
        }