public static HRESULT WriteEx(HandleRef himl, ILP dwFlags, Ole32.IStream pstm)
            {
                HRESULT result = WriteEx(himl.Handle, dwFlags, pstm);

                GC.KeepAlive(himl);
                return(result);
            }
            public static BOOL Write(HandleRef himl, Ole32.IStream pstm)
            {
                BOOL result = Write(himl.Handle, pstm);

                GC.KeepAlive(himl);
                return(result);
            }
Example #3
0
 public void DocumentComplete(object pDisp, ref object urlObject)
 {
     Debug.Assert(urlObject is null || urlObject is string, "invalid url");
     _haveNavigated = true;
     if (_parent.documentStreamToSetOnLoad != null && (string)urlObject == "about:blank")
     {
         HtmlDocument htmlDocument = _parent.Document;
         if (htmlDocument != null)
         {
             Ole32.IPersistStreamInit psi = htmlDocument.DomDocument as Ole32.IPersistStreamInit;
             Debug.Assert(psi != null, "The Document does not implement IPersistStreamInit");
             Ole32.IStream iStream = (Ole32.IStream) new Ole32.GPStream(
                 _parent.documentStreamToSetOnLoad);
             psi.Load(iStream);
             htmlDocument.Encoding = "unicode";
         }
         _parent.documentStreamToSetOnLoad = null;
     }
     else
     {
         string urlString = urlObject is null ? string.Empty : urlObject.ToString();
         WebBrowserDocumentCompletedEventArgs e = new WebBrowserDocumentCompletedEventArgs(
             new Uri(urlString));
         _parent.OnDocumentCompleted(e);
     }
 }
            public NativeImageList(Ole32.IStream pstm)
            {
                IntPtr himl;

                lock (s_syncLock)
                {
                    himl = ComCtl32.ImageList.Read(pstm);
                    Init(himl);
                }
            }
Example #5
0
            private unsafe object GetDataFromOleIStream(string format)
            {
                FORMATETC formatetc = new FORMATETC();
                STGMEDIUM medium    = new STGMEDIUM();

                formatetc.cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id));
                formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatetc.lindex   = -1;
                formatetc.tymed    = TYMED.TYMED_ISTREAM;

                medium.tymed = TYMED.TYMED_ISTREAM;

                // Limit the # of exceptions we may throw below.
                if ((int)HRESULT.S_OK != QueryGetDataUnsafe(ref formatetc))
                {
                    return(null);
                }

                try
                {
                    innerData.GetData(ref formatetc, out medium);
                }
                catch
                {
                    return(null);
                }

                if (medium.unionmember != IntPtr.Zero)
                {
                    Ole32.IStream pStream = (Ole32.IStream)Marshal.GetObjectForIUnknown(medium.unionmember);
                    Marshal.Release(medium.unionmember);
                    pStream.Stat(out Ole32.STATSTG sstg, Ole32.STATFLAG.STATFLAG_DEFAULT);

                    IntPtr hglobal = Kernel32.GlobalAlloc(
                        Kernel32.GMEM.MOVEABLE | Kernel32.GMEM.DDESHARE | Kernel32.GMEM.ZEROINIT,
                        (uint)sstg.cbSize);
                    IntPtr ptr = Kernel32.GlobalLock(hglobal);
                    pStream.Read((byte *)ptr, (uint)sstg.cbSize, null);
                    Kernel32.GlobalUnlock(hglobal);

                    return(GetDataFromHGLOBAL(format, hglobal));
                }

                return(null);
            }
Example #6
0
            public void DocumentComplete(object pDisp, ref object urlObject)
            {
                Debug.Assert(urlObject is null || urlObject is string, "invalid url");
                _haveNavigated = true;
                if (_parent.documentStreamToSetOnLoad is not null && (string)urlObject == "about:blank")
                {
                    HtmlDocument htmlDocument = _parent.Document;
                    if (htmlDocument is not null)
                    {
                        Ole32.IPersistStreamInit psi = htmlDocument.DomDocument as Ole32.IPersistStreamInit;
                        Debug.Assert(psi is not null, "The Document does not implement IPersistStreamInit");
                        Ole32.IStream iStream = (Ole32.IStream) new Ole32.GPStream(
                            _parent.documentStreamToSetOnLoad);
                        psi.Load(iStream);
                        htmlDocument.Encoding = "unicode";
                    }

                    _parent.documentStreamToSetOnLoad = null;
                }
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing && comStream is not null)
         {
             try
             {
                 comStream.Commit(Ole32.STGC.DEFAULT);
             }
             catch (Exception)
             {
             }
         }
         // Can't release a COM stream from the finalizer thread.
         comStream = null;
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
 public DataStreamFromComStream(Ole32.IStream comStream) : base()
 {
     this.comStream = comStream;
 }
 public static extern HRESULT WriteEx(IntPtr himl, ILP dwFlags, Ole32.IStream pstm);
Example #10
0
            private unsafe object GetDataFromOleIStream(string format)
            {
                FORMATETC formatetc = new FORMATETC();
                STGMEDIUM medium    = new STGMEDIUM();

                formatetc.cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id));
                formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
                formatetc.lindex   = -1;
                formatetc.tymed    = TYMED.TYMED_ISTREAM;

                // Limit the # of exceptions we may throw below.
                if ((int)HRESULT.S_OK != QueryGetDataUnsafe(ref formatetc))
                {
                    return(null);
                }

                try
                {
                    innerData.GetData(ref formatetc, out medium);
                }
                catch
                {
                    return(null);
                }

                Ole32.IStream pStream = null;
                IntPtr        hglobal = IntPtr.Zero;

                try
                {
                    if (medium.tymed == TYMED.TYMED_ISTREAM && medium.unionmember != IntPtr.Zero)
                    {
                        pStream = (Ole32.IStream)Marshal.GetObjectForIUnknown(medium.unionmember);
                        pStream.Stat(out Ole32.STATSTG sstg, Ole32.STATFLAG.DEFAULT);

                        hglobal = Kernel32.GlobalAlloc(
                            Kernel32.GMEM.MOVEABLE | Kernel32.GMEM.DDESHARE | Kernel32.GMEM.ZEROINIT,
                            (uint)sstg.cbSize);
                        // not throwing here because the other out of memory condition on GlobalAlloc
                        // happens inside innerData.GetData and gets turned into a null return value
                        if (hglobal == IntPtr.Zero)
                        {
                            return(null);
                        }
                        IntPtr ptr = Kernel32.GlobalLock(hglobal);
                        pStream.Read((byte *)ptr, (uint)sstg.cbSize, null);
                        Kernel32.GlobalUnlock(hglobal);

                        return(GetDataFromHGLOBAL(format, hglobal));
                    }

                    return(null);
                }
                finally
                {
                    if (hglobal != IntPtr.Zero)
                    {
                        Kernel32.GlobalFree(hglobal);
                    }

                    if (pStream != null)
                    {
                        Marshal.ReleaseComObject(pStream);
                    }

                    Ole32.ReleaseStgMedium(ref medium);
                }
            }
 public static extern BOOL Write(IntPtr himl, Ole32.IStream pstm);
 public static extern IntPtr Read(Ole32.IStream pstm);