PreviousArticleHttp://blog.csdn.net/norsd/archive/2008/09/13/2921389.aspx implements a webbrowser.
However, all things are not perfect. Some netizens recently asked if release is required to implement the functions of the gethtmldocumentx series.
At that time, I did not need to answer the question. I thought like this:
The webbrowser class only provides one (series) ihtmldocumentx * pointer. In the analysis structure, release. This implementation sounds good, and the actual operation seems no problem.
Coincidentally, the problem was finally discovered recently.
Consider the following situation:
1. Open nothere.html
2. If the page cannot be opened, webbrowser will try again.
3. If you jump to another page immediately, webbrowser will generate a new idocument object.
At this time, our ihtmldocumentx * Pointer Points to the previous nothere.html
Only get_document can obtain the document of the current page.
SoCodeThis should be changed:
Ihtmldocument2 * <br/> webbrowser: gethtmldocument2 () <br/>{< br/> If (_ phtmldoc2! = NULL) <br/> _ phtmldoc2-> release (); <br/> _ phtmldoc2 = NULL; <br/> iwebbrowser2 * pwb2 = NULL; <br/> idispatch * PDP = NULL; </P> <p> nulltest_ AE (pwb2 = getwebbrowser2 ()); <br/> hrtest_e (pwb2-> get_document (& PDP); <br/> nulltest_e (PDP); // if the document does not exist in IE7, then pwb2-> get_document will return an error, but IE6 will not have any HR error, it just makes PDP = NULL. </P> <p> hrtest_e (PDP-> QueryInterface (iid_ihtmldocument2, (void **) & _ phtmldoc2); <br/> return _ phtmldoc2; <br/> return: <br/> return NULL; <br/>}
P.s: ihtmldcoumentx, which indicates ihtmldocument, ihtmldocument2, and so on.