Thread: TCppWebBrowser question

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    1

    TCppWebBrowser question

    after including TCppWebBrowser component in Borland c++ builder 6 and downloading 1 or more HTML documents i'd like to save the raw HTML code in a file whoose name i generate automatically (i.e. if there are few files then they are called 1.txt, 2.txt etc). so that i don't have to do all that manually.
    the problem: how do i get the source code from the TCppWebBrowser component. there's a function called ExecWB that takes a TVariant as an argument (among other things) that specifies path & file name but i can't get it to work. the programm runs fine but i get no output and no file created. also i'm not sure if i initialize the damn TVariant (or VARIANT, whichever) variable & allocate memory for the string that i store in it because i couldn't find any speciffic instructions on it, so the problem might be there.
    there's also a TCppWebBrowser->Document property but it's extremely complicated to get to it's COM proberties such as "body" etc.
    i even tried the older HTTP client component and stuff from mshtml.h but it won't take newer html files.

    anyone knows an easy way to get source code out of TCppWebBrowser component? i mean it souldn't be so hard to do such a simple thing

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    1

    TCppWebBrowser To HTML

    Hi,

    I got this code from another website, and I am posting it here just in case more people need to work with the TCppWebBrowser.
    Hopefully Borland will improve in component in the next Builder version.

    Cheers,
    Mick

    Original link:
    http://www.tek-tips.com/viewthread.cfm?qid=327272

    Just copy/paste this code and you will end up with an AnsiString with the HTML. You can do whatever you want with that afterwards...

    My code after copying/pasting and adapting the one from the link above:

    Code:
     IHTMLDocument2* htm = NULL; // #include <mshtml.h>
    
      AnsiString Source;
    
      if(CppWebBrowser1->Document)
      {
        if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&htm)))
        {
          IPersistStreamInit* spPsi = NULL;    // ocidl.h
          if(SUCCEEDED(htm->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&spPsi)) && spPsi)
          {
            IStream *spStream = NULL;            // objidl.h
            OleCheck(CreateStreamOnHGlobal(NULL, true, &spStream));
            if(spStream)
            {
              __int64 nSize = 0;
              STATSTG ss;
              LARGE_INTEGER nMove;
              nMove.QuadPart = 0;
    
              OleCheck(spPsi->Save(spStream, true));
              OleCheck(spStream->Seek(nMove, STREAM_SEEK_SET, (ULARGE_INTEGER*)&nSize));
              OleCheck(spStream->Stat(&ss, STATFLAG_NONAME));
    
              nSize = ss.cbSize.QuadPart;
    
              Source.SetLength(nSize);
              OleCheck(spStream->Read((void *)Source.data(), nSize, (ULONG*)&nSize));
              OleCheck(spStream->Release());
            }
            spPsi->Release();
          }
          htm->Release();
        }
      }
    
      MemoResults->Lines->Add(Source);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM