i have some fine code to save the html-code from TcppWebBrowser. This
code works on all Win95/98/ME Systems and on my Notebook with XP Pro
SP1. Some customers told me, that the software get a access violation.
At a time, i could find the same result on a desktop-PC with XP Pro SP
1a. Could this be?
If i look at pMemStream->Memory, i get always NULL.
TMemoryStream* pMemStream=new TMemoryStream();
if(pMemStream && pCppWebBrowser)
{
IPersistStreamInit* pPSI;
IHTMLDocument2 *htm;
pMemStream->Seek(0, 0);
if(!pCppWebBrowser->Document)
{
while(!pCppWebBrowser->Document)
Application->ProcessMessages();
}
TStreamAdapter* pStreamAdapter = new TStreamAdapter(
pMemStream, soReference);
if(SUCCEEDED(pCppWebBrowser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&htm))
&& (bool(htm))){
if(
SUCCEEDED(htm->QueryInterface(IID_IPersistStreamInit,(LPVOID*)&pPSI)) &&
(bool(pPSI)) ){
pPSI->Save(*pStreamAdapter,false);
pPSI->Release();
}
htm->Release();
}
delete pStreamAdapter;
}
But i have not found the reason, why the software works on some pc's ???
After removing this SP2, the software works without any problem ???
What can i do. I think this belongs to many other software.
> TMemoryStream* pMemStream=new TMemoryStream();
> if(pMemStream && pCppWebBrowser)
The 'new' operator throws an exception if it fails. You don't need to check
for a NULL pointer being returned because one won't be returned in the first
place.
> IPersistStreamInit* pPSI;
> IHTMLDocument2 *htm;
You should initialize your pointers to NULL.
> pMemStream->Seek(0, 0);
There is no need to seek an empty stream.
> if(!pCppWebBrowser->Document)
> {
> while(!pCppWebBrowser->Document)
> Application->ProcessMessages();
> }
You should be testing the ReadyState property instead. The Document
property can contain a non-NULL value before the document is actually ready
to be used.
>
if(SUCCEEDED(pCppWebBrowser->Document->QueryInterface(IID_IHTMLDocument2,(LP
VOID*)&htm))
> && (bool(htm))){
Why are you converting the interface pointer to a bool? You should not be
doing that.
Try this code instead:
#include <utilcls.h>
#include <memory>
if( pCppWebBrowser )
{
while( pCppWebBrowser->ReadyState != READYSTATE_COMPLETE )
Application->ProcessMessages();
TComInterface<IHTMLDocument2> htm;
pCppWebBrowser->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&htm);
if( htm )
{
TComInterface<IPersistStreamInit> pPSI;
htm->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&pPSI);
if( pPSI )
{
std::auto_ptr<TMemoryStream> MemStream(new TMemoryStream);
std::auto_ptr<TStreamAdapter> StreamAdapter(new
TStreamAdapter(MemStream.get(), soReference));
if( SUCCEEDED(pPSI->Save(*pStreamAdapter, FALSE)) )
{
// use pMemStream as needed...
}
}
}
}
Gambit
There are a few of pages, which could not be loaded about a stream. If i
go directly to the url, all works right, but if i go with a link in
TCppWebBrowser to this page it don't work. There is always a zero
stream. I`m confused. This happens about the last 2 weeks. But this
always happens only with ebay article pages. All other pages from ebay
and other locations are working. But some PC's have no problems. So i
think there is a reason with a newer patch for internet explorer.
There are a lot of scripts on this pages. Every time there is a
Skript-Error. I have filtered the pages and remove some skripts. But if
i could not load to stream, this couldn't work. So tomorrow i have a
look at this.
Where can i get samples about working with Mozilla or Fireball?
Michael
In the first step i wanted to load the page with indy or fastnet, but
the page is loaded in more steps.
michael
Michael,
This may not be the cause of your problem, but you might want to check
that though : IE (and therfore TCppWebBrowser) only 'processes' the
document when a minimum few 256 bytes or so are loaded in the
document. If this amount is not reached, the document loads (you can
see it) but you won't be able to fetch the source or use DHTML against
it.
I also found that when the page is served using certain apache servers
with mod_gzip, this same behaviour happens even more. What a bore.
Now I only use MSXML->IXMLHTTPRequest to get web pages sources, as it
is much more flexible and accurate.
Bertrand