473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2718

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

Similar topics

3
by: Frédéric Manzanares | last post by:
hello, my problem: I want to habe one Class with write and read in a file. i have overloaded the operator >> and <<. class c_File { public : fstream fs;
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
0
by: Slawomir Nasiadka | last post by:
Hi, I'am new to this group so I would like to say "Hello" everyone and here is my problem: I'm writing a simple application (code is at the end of this message) witch would list all mails...
9
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
12
by: Julian | last post by:
Hi, I am having problems with a function that I have been using in my program to read sentences from a 'command file' and parse them into commands. the surprising thing is that the program works...
2
by: sri | last post by:
I think the following question is related to this group that is why I am posting The question is: I am reading bytes from binary file. At a particular position the byte value is "FF". I am...
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
2
by: david.crow | last post by:
Given the following input file: bob 1 2 3 4 5 mary 2 3 4 5 6 7 susan 3 4 5 6 7 8 9 This code snippet does not read it correctly: class Student {
9
by: Eric Lilja | last post by:
Hi! I have a program with a class that needs to be able to write itself to a file in clear text format. The file has two integers and vector of struct objects. The struct has a string that can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.