Exemplo n.º 1
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.º 2
0
 /// <summary>
 /// Sets the length of the stream
 /// </summary>
 /// <param name="Value">new length of the stream</param>
 public override void SetLength(long Value)
 {
     if (fileStream == null)
     {
         throw new ObjectDisposedException("fileStream", "storage stream no longer available");
     }
     fileStream.SetSize(Value);
 }
Exemplo n.º 3
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;
        }