Filterhead
Programmer
I tried a lot of options but I don't seem to get it to work.
I actually just want to read a text file which is hosted somewhere and return the value as a string.
I found this code for Visual Basic:
Form1.browser.Document.documentElement.innerHTML
But there's no such option as documentElement in Document
Thanks for your time.
*Edit* Just found a neat 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);
I actually just want to read a text file which is hosted somewhere and return the value as a string.
I found this code for Visual Basic:
Form1.browser.Document.documentElement.innerHTML
But there's no such option as documentElement in Document
Thanks for your time.
*Edit* Just found a neat 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);