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
TCppWebBrowser To HTML
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.
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:
IHTMLDocument2* htm = NULL; // #include <mshtml.h>
IPersistStreamInit* spPsi = NULL; // ocidl.h
if(SUCCEEDED(htm->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&spPsi)) && spPsi)
IStream *spStream = NULL; // objidl.h
OleCheck(CreateStreamOnHGlobal(NULL, true, &spStream));
__int64 nSize = 0;
nMove.QuadPart = 0;
OleCheck(spStream->Seek(nMove, STREAM_SEEK_SET, (ULARGE_INTEGER*)&nSize));
nSize = ss.cbSize.QuadPart;
OleCheck(spStream->Read((void *)Source.data(), nSize, (ULONG*)&nSize));