By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,903 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,903 IT Pros & Developers. It's quick & easy.

Problem reading from IStream (C#)

P: 1
I wouldn't normally beg but my dissertation is due in, in a couple of weeks and I am in way over my head here.. Fixing this issue will make or break the project and my degree..

The goal is to extract the raw html from Internet Explorer using a BHO. When accessing the HTML via the mshtml.HTMLDocument (DOM) object you get a version of the HTML that is different from what you see when you "right click --> view source". IE changes the code for some reason..

The BHO is written and working, and I have even managed to extract the raw html from the browser by following the posts here:

I then tried to read in a couple of HTML documents. The smaller document works fine, no problems at all. With the larger document, it fails to read the entire page, however if you debug the code and step through it works fine!

In reference to the code below, increasing the value in GetStream() makes no difference. If anyone can provide sample code as a solution I would be so grateful I can't even put it into words!

Expand|Select|Wrap|Line Numbers
  1. HTMLDocument document = (HTMLDocument)base.Explorer.Document;
  2. IPersistStreamInit ips = (IPersistStreamInit)document;
  4. IStream strm = RawHtml.GetStream(2048);
  5. ips.Save(strm, false);
  7. string rawhtml = RawHtml.StreamToString(strm);
  12. class RawHtml
  13.     {
  14.         [DllImport("ole32.dll")]
  15.         public extern static void CreateStreamOnHGlobal(IntPtr hGlobal, bool fDelete, ref IStream stm);
  17.         [DllImport("ole32.dll")]
  18.         public extern static void GetHGlobalFromStream(IStream stm, ref IntPtr hGlobal);
  20.         public static IStream GetStream(int size)
  21.         {
  22.             IntPtr iptr = Marshal.AllocHGlobal(size);
  23.             IStream strm = null;
  25.             CreateStreamOnHGlobal(iptr, true, ref strm);
  26.             return strm;
  27.          }
  29.         public static string StreamToString(IStream strm) 
  30.         {
  31.             IntPtr iptr = new IntPtr();
  32.             string text;
  34.             GetHGlobalFromStream(strm, ref iptr);
  35.             text = Marshal.PtrToStringAnsi(iptr);
  37.             return text;
  38.         }
  39.     }
  41.     [ComVisible(false), ComImport(), Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"),InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
  42.     public interface IPersistStreamInit
  43.     {
  44.          void GetClassID(ref Guid pClassID);
  45.          [PreserveSig()]
  46.          int IsDirty();
  47.          [PreserveSig()]
  48.          int Load(IStream pstm);
  49.          [PreserveSig()]
  50.          int Save(IStream pstm, bool fClearDirty);
  51.          [PreserveSig()]
  52.          int GetSizeMax([InAttribute(), Out(), MarshalAs(UnmanagedType.U8)] ref long pcbSize);
  53.          [PreserveSig()]
  54.          int InitNew();
  55.      }
Thank you so much in advance..

Mar 31 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.