code_junkie

How do I retrieve IPIEHTMLDocument2 interface on IE Mobile

Nov 10th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. IUnknown *site = pUnkSite; /* retrieved from IE7 during SetSite() call */
  2. IServiceProvider *sp = NULL;
  3. IHTMLWindow2 *win = NULL;
  4. IHTMLDocument2 *doc = NULL;
  5.  
  6. if(site) {
  7. site->QueryInterface(IID_IServiceProvider, (void **)&sp);
  8. if(sp) {
  9. sp->QueryService(IID_IHTMLWindow2, IID_IHTMLWindow2, (void **)&win);
  10. if(win) {
  11. win->get_document(&doc);
  12. }
  13. }
  14. }
  15. if(doc) {
  16. /* found */
  17. }
  18.  
  19. IUnknown *site = pUnkSite; /* retrieved from PIE during SetSite() call */
  20. IPIEHTMLWindow2 *win = NULL;
  21. IPIEHTMLDocument1 *tmp = NULL;
  22. IPIEHTMLDocument2 *doc = NULL;
  23.  
  24. if(site) {
  25. site->QueryInterface(__uuidof(*win), (void **)&win);
  26. if(win) { /* never the case */
  27. win->get_document(&tmp);
  28. if(tmp) {
  29. tmp->QueryInterface(__uuidof(*doc), (void **)&doc);
  30. }
  31. }
  32. }
  33. if(doc) {
  34. /* found */
  35. }
  36.  
  37. #ifdef WINCE
  38. // We can't get IWebBrowser2 for WinCE.
  39. #else
  40. HRESULT ActiveXUtils::GetWebBrowser2(IUnknown *site, IWebBrowser2 **browser2) {
  41. CComQIPtr<IServiceProvider> service_provider = site;
  42. if (!service_provider) { return E_FAIL; }
  43.  
  44. return service_provider->QueryService(SID_SWebBrowserApp,
  45. IID_IWebBrowser2,
  46. reinterpret_cast<void**>(browser2));
  47. }
  48. #endif
  49.  
  50.  
  51. HRESULT ActiveXUtils::GetHtmlDocument2(IUnknown *site,
  52. IHTMLDocument2 **document2) {
  53. HRESULT hr;
  54.  
  55. #ifdef WINCE
  56. // Follow path Window2 -> Window -> Document -> Document2
  57. CComPtr<IPIEHTMLWindow2> window2;
  58. hr = GetHtmlWindow2(site, &window2);
  59. if (FAILED(hr) || !window2) { return false; }
  60. CComQIPtr<IPIEHTMLWindow> window = window2;
  61. CComPtr<IHTMLDocument> document;
  62. hr = window->get_document(&document);
  63. if (FAILED(hr) || !document) { return E_FAIL; }
  64. return document->QueryInterface(__uuidof(*document2),
  65. reinterpret_cast<void**>(document2));
  66. #else
  67. CComPtr<IWebBrowser2> web_browser2;
  68. hr = GetWebBrowser2(site, &web_browser2);
  69. if (FAILED(hr) || !web_browser2) { return E_FAIL; }
  70.  
  71. CComPtr<IDispatch> doc_dispatch;
  72. hr = web_browser2->get_Document(&doc_dispatch);
  73. if (FAILED(hr) || !doc_dispatch) { return E_FAIL; }
  74.  
  75. return doc_dispatch->QueryInterface(document2);
  76. #endif
  77. }
  78.  
  79.  
  80. HRESULT ActiveXUtils::GetHtmlWindow2(IUnknown *site,
  81. #ifdef WINCE
  82. IPIEHTMLWindow2 **window2) {
  83. // site is javascript IDispatch pointer.
  84. return site->QueryInterface(__uuidof(*window2),
  85. reinterpret_cast<void**>(window2));
  86. #else
  87. IHTMLWindow2 **window2) {
  88. CComPtr<IHTMLDocument2> html_document2;
  89. // To hook an event on a page's window object, follow the path
  90. // IWebBrowser2->document->parentWindow->IHTMLWindow2
  91.  
  92. HRESULT hr = GetHtmlDocument2(site, &html_document2);
  93. if (FAILED(hr) || !html_document2) { return E_FAIL; }
  94.  
  95. return html_document2->get_parentWindow(window2);
  96. #endif
  97. }
Add Comment
Please, Sign In to add comment