Exemplo n.º 1
0
        void UCOMIStream.CopyTo(UCOMIStream destination, long count, IntPtr pcbRead, IntPtr pcbWritten)
        {
            //////////
            // Copy the lot using 4k chunks
            //////////
            byte [] _buffer    = new byte[4096];
            int     _cbRead    = 0;
            int     _cbWritten = 0;

            while (count > 0)
            {
                int _chunk     = (int)Math.Min(count, _buffer.Length);
                int _chunkRead = this.Read(_buffer, _cbRead, _chunk);
                destination.Write(_buffer, _chunk, IntPtr.Zero);

                _cbRead    += _chunkRead;
                _cbWritten += _chunkRead;
            }

            //////////
            // Update the counts, if they were provided
            //////////
            if (pcbRead != IntPtr.Zero)
            {
                Marshal.WriteInt64(pcbRead, _cbRead);
            }

            if (pcbWritten != IntPtr.Zero)
            {
                Marshal.WriteInt64(pcbWritten, _cbWritten);
            }
        }
Exemplo n.º 2
0
        void foo(UCOMIStream iStream)
        {
            // Load the Encrypted file into a stream.
            FileStream fsIn = new FileStream("C:\\test.pdf", FileMode.Open, FileAccess.Read);

            // Create a MemoryStream to hold the decrypted data.
            MemoryStream ms = new MemoryStream();

            // Create a reader for the data.
            BinaryReader r = new BinaryReader(ms);

            // Get length of the file.
            int fileLen = Convert.ToInt32(ms.Length);

            // Create a buffer for the data.
            byte[] fileBytes = new byte[fileLen];

            // Read the data from Memory
            for (int i = 0; i < fileLen; i++)
            {
                fileBytes[i] = r.ReadByte();
            }

            // declare the COM stream
            //UCOMIStream iStream;

            // Write the data from buffer into COM Stream
            iStream.Write(fileBytes, fileLen, System.IntPtr.Zero);

            // Set size of COM stream
            iStream.SetSize(fileLen);
        }
Exemplo n.º 3
0
        void UCOMIStream.CopyTo(UCOMIStream destination, long count, IntPtr pcbRead, IntPtr pcbWritten)
        {
            //////////
            // Copy the lot using 4k chunks
            //////////
            byte [] _buffer = new byte[4096];
            int _cbRead = 0;
            int _cbWritten = 0;
            while (count > 0)
            {
                int _chunk = (int)Math.Min(count, _buffer.Length);
                int _chunkRead = this.Read(_buffer, _cbRead, _chunk);
                destination.Write(_buffer, _chunk, IntPtr.Zero);

                _cbRead += _chunkRead;
                _cbWritten += _chunkRead;
            }

            //////////
            // Update the counts, if they were provided
            //////////
            if (pcbRead != IntPtr.Zero)
            {
                Marshal.WriteInt64(pcbRead, _cbRead);
            }

            if (pcbWritten != IntPtr.Zero)
            {
                Marshal.WriteInt64(pcbWritten, _cbWritten);
            }
        }
        public static void LoadGraphFile(IGraphBuilder graphBuilder, string fileName)
        {
            int      hr      = 0;
            IStorage storage = null;

#if USING_NET11
            UCOMIStream stream = null;
#else
            IStream stream = null;
#endif

            if (graphBuilder == null)
            {
                throw new ArgumentNullException("graphBuilder");
            }

            try
            {
                if (NativeMethods.StgIsStorageFile(fileName) != 0)
                {
                    throw new ArgumentException(fileName);
                }

                hr = NativeMethods.StgOpenStorage(
                    fileName,
                    null,
                    STGM.Transacted | STGM.Read | STGM.ShareDenyWrite,
                    IntPtr.Zero,
                    0,
                    out storage
                    );

                Marshal.ThrowExceptionForHR(hr);

                hr = storage.OpenStream(
                    @"ActiveMovieGraph",
                    IntPtr.Zero,
                    STGM.Read | STGM.ShareExclusive,
                    0,
                    out stream
                    );

                Marshal.ThrowExceptionForHR(hr);

                hr = (graphBuilder as IPersistStream).Load(stream);
                Marshal.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (stream != null)
                {
                    Marshal.ReleaseComObject(stream);
                }
                if (storage != null)
                {
                    Marshal.ReleaseComObject(storage);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Enumerates an Interop.IStorage object and creates the internal file object collection
        /// </summary>
        /// <param name="BasePath">Sets the base url for the storage files</param>
        /// <param name="enumStorage">storage to enumerate</param>
        protected void EnumIStorageObject(Interop.IStorage enumStorage, string BasePath)
        {
            Interop.IEnumSTATSTG iEnumSTATSTG;

            STATSTG sTATSTG;

            int i;

            enumStorage.EnumElements(0, IntPtr.Zero, 0, out iEnumSTATSTG);
            iEnumSTATSTG.Reset();
            while (iEnumSTATSTG.Next(1, out sTATSTG, out i) == (int)Interop.S_OK)
            {
                if (i == 0)
                {
                    break;
                }

                FileObject newFileObj = new FileObject();
                newFileObj.FileType = sTATSTG.type;
                switch (sTATSTG.type)
                {
                case 1:
                    Interop.IStorage iStorage = enumStorage.OpenStorage(sTATSTG.pwcsName, IntPtr.Zero, 16, IntPtr.Zero, 0);
                    if (iStorage != null)
                    {
                        string str = String.Concat(BasePath, sTATSTG.pwcsName.ToString());
                        newFileObj.FileStorage = iStorage;
                        newFileObj.FilePath    = BasePath;
                        newFileObj.FileName    = sTATSTG.pwcsName.ToString();
                        foCollection.Add(newFileObj);
                        EnumIStorageObject(iStorage, str);
                    }
                    break;

                case 2:
                    UCOMIStream uCOMIStream = enumStorage.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0);
                    newFileObj.FilePath   = BasePath;
                    newFileObj.FileName   = sTATSTG.pwcsName.ToString();
                    newFileObj.FileStream = uCOMIStream;
                    foCollection.Add(newFileObj);
                    break;

                case 4:
                    Trace.WriteLine("Ignoring IProperty type ...");
                    break;

                case 3:
                    Trace.WriteLine("Ignoring ILockBytes type ...");
                    break;

                default:
                    Trace.WriteLine("Unknown object type ...");
                    break;
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Closes the storage stream
 /// </summary>
 public override void Close()
 {
     if (fileStream != null)
     {
         fileStream.Commit(0);
         Marshal.ReleaseComObject(fileStream);
         fileStream = null;
         GC.SuppressFinalize(this);
     }
 }
        public static void SaveGraphFile(IGraphBuilder graphBuilder, string fileName)
        {
            int      hr      = 0;
            IStorage storage = null;

#if USING_NET11
            UCOMIStream stream = null;
#else
            IStream stream = null;
#endif

            if (graphBuilder == null)
            {
                throw new ArgumentNullException("graphBuilder");
            }

            try
            {
                hr = NativeMethods.StgCreateDocfile(
                    fileName,
                    STGM.Create | STGM.Transacted | STGM.ReadWrite | STGM.ShareExclusive,
                    0,
                    out storage
                    );

                Marshal.ThrowExceptionForHR(hr);

                hr = storage.CreateStream(
                    @"ActiveMovieGraph",
                    STGM.Write | STGM.Create | STGM.ShareExclusive,
                    0,
                    0,
                    out stream
                    );

                Marshal.ThrowExceptionForHR(hr);

                hr = (graphBuilder as IPersistStream).Save(stream, true);
                Marshal.ThrowExceptionForHR(hr);

                hr = storage.Commit(STGC.Default);
                Marshal.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (stream != null)
                {
                    Marshal.ReleaseComObject(stream);
                }
                if (storage != null)
                {
                    Marshal.ReleaseComObject(storage);
                }
            }
        }
Exemplo n.º 8
0
 protected void Dispose(bool isDisposing)
 {
     if (_Stream != null)
     {
         if (isDisposing)
         {
             _Stream.Commit(0);
         }
         Marshal.ReleaseComObject(_Stream);
         _Stream = null;
     }
 }
Exemplo n.º 9
0
        // Not used - But there are things here that may be useful some day
#if false
        void TestSave2()
        {
            int         hr;
            UCOMIStream uis = null;
            long        siz;

            hr = m_ips.GetSizeMax(out siz);
            myIStorage iStore = null;

            hr = StgCreateDocfile(@"C:\foo.out",
                                  //STGM.DIRECT|STGM.CREATE|STGM.READWRITE|STGM.SHARE_EXCLUSIVE,
                                  STGM.CREATE | STGM.WRITE | STGM.SHARE_EXCLUSIVE,
                                  0,
                                  ref iStore);
            DsError.ThrowExceptionForHR(hr);
            uis = iStore as UCOMIStream;

            //hr = iStore.CreateStream("asdf", STGM.DIRECT|STGM.CREATE|STGM.READWRITE|STGM.SHARE_EXCLUSIVE, 0, 0, out uis);
            hr = iStore.CreateStream("asdf", STGM.CREATE | STGM.WRITE | STGM.SHARE_EXCLUSIVE, 0, 0, out uis);

            hr = OleSaveToStream(m_ips, uis);

            hr = StgCreateStorageEx(@"c:\foo.out",
                                    (STGM)0,
                                    (STGFMT)0,
                                    0,
                                    IntPtr.Zero,
                                    IntPtr.Zero,
                                    typeof(myIStorage).GUID,
                                    ref iStore);
            DsError.ThrowExceptionForHR(hr);

            string s = typeof(UCOMIStream).GUID.ToString();

            // Create the stream (with no initial memory allocated)
            IntPtr ip = Marshal.AllocCoTaskMem((int)siz);

            ip = GlobalAlloc(0, (int)siz);
            hr = CreateStreamOnHGlobal(ip, false, out uis);
            //uis.SetSize(siz * 2);

            byte[] b = new byte[3];
            b[0] = 65;
            b[1] = 66;
            b[2] = 67;

            uis.Write(b, b.Length, IntPtr.Zero);

            hr = m_ips.Save(uis, true);
            DsError.ThrowExceptionForHR(hr);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Opens an UCOMIStream and returns the associated file object
        /// </summary>
        /// <param name="parentStorage">storage used to open the stream</param>
        /// <param name="fileName">filename of the stream</param>
        /// <returns>A <see cref="FileObject">FileObject</see> instance if the file was found, otherwise null.</returns>
        public FileObject OpenUCOMStream(Interop.IStorage parentStorage, string fileName)
        {
            if (parentStorage == null)
            {
                parentStorage = storage;
            }

            FileObject retObject = null;

            STATSTG sTATSTG;

            sTATSTG.pwcsName = fileName;
            sTATSTG.type     = 2;

            try
            {
                retObject = new FileObject();

                UCOMIStream uCOMIStream = parentStorage.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0);

                if (uCOMIStream != null)
                {
                    retObject.FileType   = sTATSTG.type;
                    retObject.FilePath   = "";
                    retObject.FileName   = sTATSTG.pwcsName.ToString();
                    retObject.FileStream = uCOMIStream;
                }
                else
                {
                    retObject = null;
                }
            }
            catch (Exception ex)
            {
                retObject = null;

                Trace.WriteLine("ITStorageWrapper.OpenUCOMStream() - Failed for file '" + fileName + "'");
                Trace.Indent();
                Trace.WriteLine("Exception: " + ex.Message);
                Trace.Unindent();
            }

            return(retObject);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Called to save the settings data to the given stream.
        /// </summary>
        /// <param name="stm">stream to save the settings to</param>
        /// <param name="clearDirty">if true, clear our 'dirty' flag</param>
        public void Save(UCOMIStream stm, bool clearDirty)
        {
            MemoryStream memStream = new MemoryStream();
            BinaryWriter binWriter = new BinaryWriter(memStream);

            // first our version
            binWriter.Write(dataVersion);
            // then the data.
            binWriter.Write(itemStart);
            // cleanup
            binWriter.Flush();

            // write to actual output stream
            byte[] data = memStream.ToArray();
            stm.Write(data, data.Length, IntPtr.Zero);

            if (clearDirty)
            {
                isDirty = false;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Called to read the settings data from the given stream.
        /// </summary>
        /// <param name="stm">stream from which the settings can be read</param>
        public void Load(UCOMIStream stm)
        {
            const int maxDataLen = 1000; // read a large enough number of bytes for us.

            byte[] data = new byte[maxDataLen];
            stm.Read(data, data.Length, IntPtr.Zero);

            MemoryStream memStream = new MemoryStream(data);
            BinaryReader binReader = new BinaryReader(memStream);

            int version = binReader.ReadInt32();

            if (version != dataVersion)
            {
                MessageBox.Show("Invalid data version, using default values");
            }
            else
            {
                // valid version, continue reading data.
                itemStart = binReader.ReadInt32();
            }

            Initialize();
        }
 static extern int CreateStreamOnHGlobal(IntPtr hGlobal, bool fDeleteOnRelease, out UCOMIStream ppstm);
 private static extern int GdipLoadImageFromStream(UCOMIStream istream, out IntPtr image);
Exemplo n.º 15
0
 public void Clone(out UCOMIStream ppstm)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 public void CopyTo(UCOMIStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 17
0
 public OleStream(UCOMIStream stream, string name)
 {
     _Stream = stream;
     _Name   = name;
 }
Exemplo n.º 18
0
 private static extern int BindIFilterFromStream(UCOMIStream pStm,
                                                 [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter,
                                                 [Out] out IFilter ppIUnk);
Exemplo n.º 19
0
 public void CopyTo(UCOMIStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 20
0
        /// <summary>
        /// Called to save the settings data to the given stream.
        /// </summary>
        /// <param name="stm">stream to save the settings to</param>
        /// <param name="clearDirty">if true, clear our 'dirty' flag</param>
        public void Save(UCOMIStream stm, bool clearDirty)
        {
            try
            {
            MemoryStream memStream = new MemoryStream();
            BinaryWriter binWriter = new BinaryWriter(memStream);

            // first our version
            binWriter.Write(dataVersion);
            // then the data.

            // cleanup
            binWriter.Flush();

            // write to actual output stream
            byte[] data = memStream.ToArray();
            stm.Write(data, data.Length, IntPtr.Zero);

            if (clearDirty)
                isDirty = false;
            }
            catch (Exception E)
            {
                Log.Error("Save Error "+E.Message);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Called to read the settings data from the given stream.
        /// </summary>
        /// <param name="stm">stream from which the settings can be read</param>
        public void Load(UCOMIStream stm)
        {
            Log.Debug("Called Load()");
            try
            {
                const int maxDataLen = 1000;  // read a large enough number of bytes for us.
                byte[] data = new byte[maxDataLen];
                stm.Read(data, data.Length, IntPtr.Zero);

                MemoryStream memStream = new MemoryStream(data);
                BinaryReader binReader = new BinaryReader(memStream);

                int version = binReader.ReadInt32();
                if (version != dataVersion)
                {
                    // MessageBox.Show("Invalid data version, using default values");
                }
                else
                {
                    // valid version, continue reading data.

                }
            }
            catch (Exception E)
            {
                Log.Error("Load Error"+E.Message);
            }

            Initialize();
        }
Exemplo n.º 22
0
        public void LoadDocument(String documentVal)
        {
            if ((documentVal != string.Empty) | (!this.bLoadDocumentWhenReady))
            {
                //if doc is waiting to load, it is already in string variable
                sDocument = documentVal;
                this.bLoadDocumentWhenReady = false;
            }
            else
            {
                this.bLoadDocumentWhenReady = false;
                this.iLoadAttempts         += 1;
            }

            if (!IsCreated)
            {
                throw new HtmlEditorException("Document not created");
            }

            if ((this.m_htmldoc.readyState.ToLower() != "complete") & (this.m_htmldoc.readyState.ToLower() != "interactive"))
            //try to load on interactive as well as complete

            {
                if (iLoadAttempts < 2)
                {
                    this.bLoadDocumentWhenReady = true;
                    return;
                }
                else
                {
                    throw new HtmlEditorException("Document not ready");
                }
            }


            if ((sDocument == null) || (sDocument == String.Empty))
            {
                sDocument = "<html><body></body></html>";
            }

            UCOMIStream stream = null;

            if (this.mIsWin98 | this.mAlwaysLoadAnsi)
            {
                ComSupport.CreateStreamOnHGlobal(Marshal.StringToHGlobalAnsi(sDocument), 1, out
                                                 stream);
            }
            else
            {
                ComSupport.CreateStreamOnHGlobal(Marshal.StringToHGlobalUni(sDocument), 1, out
                                                 stream);
            }


            if (stream == null)
            {
                throw new HtmlEditorException("Could not allocate document stream");
            }

            if (this.mIsWin98)
            {
                //This code fixes a problem in Win98 - Framework bug? - where the string
                //is sometimes incorrectly terminated
                //It assumes an ANSI string

                ulong  thesize = 0;
                IntPtr ptr     = IntPtr.Zero;

                int iSizeOfIntPtr = Marshal.SizeOf(typeof(Int64));
                ptr = Marshal.AllocHGlobal(iSizeOfIntPtr);

                if (ptr == IntPtr.Zero)
                {
                    throw new HtmlEditorException("Could not load document");
                }

                //seek to end of stream
                stream.Seek(0, 2, ptr);
                //read the size
                thesize = (ulong)Marshal.ReadInt64(ptr);
                //free the pointer
                Marshal.FreeHGlobal(ptr);

                //2nd param, 0 is beginning, 1 is current, 2 is end

                if (thesize != (ulong)sDocument.Length + 1)
                {
                    //fix the size by truncating the stream
                    Debug.Assert(true, "Size of stream is unexpected", "The size of the stream is not equal to the length of the string passed to it.");
                    stream.SetSize((sDocument.Length) + 1);
                }
            }

            //set stream to start
            stream.Seek(0, 0, IntPtr.Zero);

            IPersistStreamInit persistentStreamInit = (IPersistStreamInit)
                                                      this.m_htmldoc;

            if (persistentStreamInit != null)
            {
                int iRetVal = 0;
                iRetVal = persistentStreamInit.InitNew();
                if (iRetVal == HRESULT.S_OK)
                {
                    //this is a fix for exception raised in UpdateUI
                    site.mFullyActive = false;

                    iRetVal = persistentStreamInit.Load(stream);

                    if (iRetVal != HRESULT.S_OK)
                    {
                        throw new HtmlEditorException("Could not load document");
                    }
                }
                else
                {
                    throw new HtmlEditorException("Could not load document");
                }
                persistentStreamInit = null;
            }
            else
            {
                throw new HtmlEditorException("Could not load document");
            }

            stream             = null;
            this.iLoadAttempts = 0;
        }
Exemplo n.º 23
0
 public void Clone(out UCOMIStream ppstm)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 24
0
        /// <summary>
        /// Called to read the settings data from the given stream.
        /// </summary>
        /// <param name="stm">stream from which the settings can be read</param>
        public void Load(UCOMIStream stm)
        {
            const int maxDataLen = 1000;  // read a large enough number of bytes for us.
              byte[] data = new byte[maxDataLen];
              stm.Read(data, data.Length, IntPtr.Zero);

              MemoryStream memStream = new MemoryStream(data);
              BinaryReader binReader = new BinaryReader(memStream);

              int version = binReader.ReadInt32();
              if (version != dataVersion) {
            MessageBox.Show("Invalid data version, using default values");
              } else {
            // valid version, continue reading data.
            itemStart = binReader.ReadInt32();
              }

              Initialize();
        }
Exemplo n.º 25
0
 void UCOMIStream.Clone(out UCOMIStream clone)
 {
     clone = this.MemberwiseClone() as UCOMIStream;
 }
Exemplo n.º 26
0
        /// <summary>
        /// Called to save the settings data to the given stream.
        /// </summary>
        /// <param name="stm">stream to save the settings to</param>
        /// <param name="clearDirty">if true, clear our 'dirty' flag</param>
        public void Save(UCOMIStream stm, bool clearDirty)
        {
            MemoryStream memStream = new MemoryStream();
              BinaryWriter binWriter = new BinaryWriter(memStream);

              // first our version
              binWriter.Write(dataVersion);
              // then the data.
              binWriter.Write(itemStart);
              // cleanup
              binWriter.Flush();

              // write to actual output stream
              byte[] data = memStream.ToArray();
              stm.Write(data, data.Length, IntPtr.Zero);

              if (clearDirty)
            isDirty = false;
        }
Exemplo n.º 27
0
 private static extern int OleSaveToStream(
     IPersistStream pPStm,  //Pointer to the interface on the object
     // to be saved
     UCOMIStream pStm       //Pointer to the destination stream to
     // which the object is saved
     );
Exemplo n.º 28
0
 /// <summary>
 /// Closes the storage stream
 /// </summary>
 public override void Close()
 {
     if (fileStream != null)
     {
         fileStream.Commit(0);
         Marshal.ReleaseComObject(fileStream);
         fileStream = null;
         GC.SuppressFinalize(this);
     }
 }
Exemplo n.º 29
0
 void UCOMIStream.Clone(out UCOMIStream clone)
 {
     clone = this.MemberwiseClone() as UCOMIStream;
 }