Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IUnknown *site = pUnkSite; /* retrieved from IE7 during SetSite() call */
- IServiceProvider *sp = NULL;
- IHTMLWindow2 *win = NULL;
- IHTMLDocument2 *doc = NULL;
- if(site) {
- site->QueryInterface(IID_IServiceProvider, (void **)&sp);
- if(sp) {
- sp->QueryService(IID_IHTMLWindow2, IID_IHTMLWindow2, (void **)&win);
- if(win) {
- win->get_document(&doc);
- }
- }
- }
- if(doc) {
- /* found */
- }
- IUnknown *site = pUnkSite; /* retrieved from PIE during SetSite() call */
- IPIEHTMLWindow2 *win = NULL;
- IPIEHTMLDocument1 *tmp = NULL;
- IPIEHTMLDocument2 *doc = NULL;
- if(site) {
- site->QueryInterface(__uuidof(*win), (void **)&win);
- if(win) { /* never the case */
- win->get_document(&tmp);
- if(tmp) {
- tmp->QueryInterface(__uuidof(*doc), (void **)&doc);
- }
- }
- }
- if(doc) {
- /* found */
- }
- #ifdef WINCE
- // We can't get IWebBrowser2 for WinCE.
- #else
- HRESULT ActiveXUtils::GetWebBrowser2(IUnknown *site, IWebBrowser2 **browser2) {
- CComQIPtr<IServiceProvider> service_provider = site;
- if (!service_provider) { return E_FAIL; }
- return service_provider->QueryService(SID_SWebBrowserApp,
- IID_IWebBrowser2,
- reinterpret_cast<void**>(browser2));
- }
- #endif
- HRESULT ActiveXUtils::GetHtmlDocument2(IUnknown *site,
- IHTMLDocument2 **document2) {
- HRESULT hr;
- #ifdef WINCE
- // Follow path Window2 -> Window -> Document -> Document2
- CComPtr<IPIEHTMLWindow2> window2;
- hr = GetHtmlWindow2(site, &window2);
- if (FAILED(hr) || !window2) { return false; }
- CComQIPtr<IPIEHTMLWindow> window = window2;
- CComPtr<IHTMLDocument> document;
- hr = window->get_document(&document);
- if (FAILED(hr) || !document) { return E_FAIL; }
- return document->QueryInterface(__uuidof(*document2),
- reinterpret_cast<void**>(document2));
- #else
- CComPtr<IWebBrowser2> web_browser2;
- hr = GetWebBrowser2(site, &web_browser2);
- if (FAILED(hr) || !web_browser2) { return E_FAIL; }
- CComPtr<IDispatch> doc_dispatch;
- hr = web_browser2->get_Document(&doc_dispatch);
- if (FAILED(hr) || !doc_dispatch) { return E_FAIL; }
- return doc_dispatch->QueryInterface(document2);
- #endif
- }
- HRESULT ActiveXUtils::GetHtmlWindow2(IUnknown *site,
- #ifdef WINCE
- IPIEHTMLWindow2 **window2) {
- // site is javascript IDispatch pointer.
- return site->QueryInterface(__uuidof(*window2),
- reinterpret_cast<void**>(window2));
- #else
- IHTMLWindow2 **window2) {
- CComPtr<IHTMLDocument2> html_document2;
- // To hook an event on a page's window object, follow the path
- // IWebBrowser2->document->parentWindow->IHTMLWindow2
- HRESULT hr = GetHtmlDocument2(site, &html_document2);
- if (FAILED(hr) || !html_document2) { return E_FAIL; }
- return html_document2->get_parentWindow(window2);
- #endif
- }
Add Comment
Please, Sign In to add comment