468,734 Members | 2,218 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,734 developers. It's quick & easy.

Problem reading from IStream (C#)

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: http://www.thescripts.com/forum/thread348964.html

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;
  3.  
  4. IStream strm = RawHtml.GetStream(2048);
  5. ips.Save(strm, false);
  6.  
  7. string rawhtml = RawHtml.StreamToString(strm);
  8.  
  9.  
  10.  
  11. [RAWHTML CLASS]
  12. class RawHtml
  13.     {
  14.         [DllImport("ole32.dll")]
  15.         public extern static void CreateStreamOnHGlobal(IntPtr hGlobal, bool fDelete, ref IStream stm);
  16.  
  17.         [DllImport("ole32.dll")]
  18.         public extern static void GetHGlobalFromStream(IStream stm, ref IntPtr hGlobal);
  19.  
  20.         public static IStream GetStream(int size)
  21.         {
  22.             IntPtr iptr = Marshal.AllocHGlobal(size);
  23.             IStream strm = null;
  24.  
  25.             CreateStreamOnHGlobal(iptr, true, ref strm);
  26.             return strm;
  27.          }
  28.  
  29.         public static string StreamToString(IStream strm) 
  30.         {
  31.             IntPtr iptr = new IntPtr();
  32.             string text;
  33.  
  34.             GetHGlobalFromStream(strm, ref iptr);
  35.             text = Marshal.PtrToStringAnsi(iptr);
  36.  
  37.             return text;
  38.         }
  39.     }
  40.  
  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.      }
  56.  
Thank you so much in advance..

Ad
Mar 31 '08 #1
0 2515

Post your reply

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

Similar topics

3 posts views Thread by Frédéric Manzanares | last post: by
19 posts views Thread by Lionel B | last post: by
reply views Thread by Slawomir Nasiadka | last post: by
12 posts views Thread by Julian | last post: by
2 posts views Thread by sri | last post: by
19 posts views Thread by rmr531 | last post: by
9 posts views Thread by Eric Lilja | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.