Ejemplo n.º 1
0
 IntPtr IBindStatusCallback.OnStopBinding(IntPtr hresult, string szError)
 {
     // Give a callback async way to avoid failures connected to the fact that
     // while being in the method the browser may be still "busy" and therefore not ready for next navigation.
     PostCompletionCallback(HResults.Equals(hresult, HResults.S_OK), szError);
     return(HResults.S_OK);
 }
Ejemplo n.º 2
0
        IntPtr IBindStatusCallback.OnDataAvailable(uint grfBSCF, uint dwSize, ref FORMATETC pformatetc, ref STGMEDIUM pstgmed)
        {
            if (pstgmed.tymed != TYMED.TYMED_ISTREAM)
            {
                throw new InvalidOperationException("This callback handler only supports IStreams.");
            }

            // assume an IStream has been requested in BindMonikerToObject
            IStream stream = (IStream)Marshal.GetObjectForIUnknown(pstgmed.unionmember);

            IntPtr hresult;
            bool   shouldContinue = true;

            do
            {
                byte[] buffer     = new byte[bufferSize];
                IntPtr pBytesRead = Marshal.AllocHGlobal(sizeof(uint));
                hresult = stream.Read(buffer, buffer.Length, pBytesRead);
                uint bytesRead = (uint)Marshal.PtrToStructure(pBytesRead, typeof(uint));
                Marshal.FreeHGlobal(pBytesRead);

                if (bytesRead > 0)
                {
                    shouldContinue = viewEvents.OnDataAvailable(buffer, (int)bytesRead);
                }
                //if (HResults.Equals(hresult, HResults.E_PENDING))
                //{
                //	Thread.Sleep(1000);
                //	hresult = HResults.S_OK;
                //}
            } while (shouldContinue && HResults.Succeeded(hresult) && !HResults.Equals(hresult, HResults.S_FALSE));

            Marshal.ReleaseComObject(stream);

            if (!shouldContinue)
            {
                Abort();
            }

            if (!HResults.Succeeded(hresult))
            {
                return(hresult);
            }

            return(HResults.S_OK);
        }
Ejemplo n.º 3
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.");
            }
        }