Search code examples
internet-explorercomdynamics-crm

How to get a COM reference to an Internet Explorer instance embedded in another application


The Dynamics plugin for Outlook displays content via an Internet Explorer embedded window. I'm trying to find a way to get at the SHDocVw.InternetExplorer COM object for that embedded window. Our application runs stand-alone (it's not an Outlook or IE add-in) and we are not at all in control of creation of the embedded IE window.

When I use:

Dim SWs As SHDocVw.ShellWindows
Set SWs = New SHDocVw.ShellWindows

the SWs collection does not contain a reference to the embedded browser in Outlook (though I do get references to regular browser windows).

Using Spy++, I see the following window hierarchy for the embedded Outlook window:

Window "xxxxxx" WindowsForms10.Window.8.app.0.5c39d4_r64_ad2
  - "" Shell Embedding
    - "" Shell DocObject View
      - "" Internet Explorer_Server

The last two windows in the hierarchy (Shell DocObject View and Internet Explorer_Server) are exactly the same as for the embedded viewer in a running Internet Explorer instance.

It seems like there must be some way to get a COM reference to these embedded browsers - any help or ideas would be greatly appreciated.


Solution

  • See KB 249232. You can get the IHTMLDocument2 pointer from the Internet Explorer_Server window using accessibility stuff. It ain't pretty, and it won't work if you're running in a different integrity level than the target process.

    Depending on what you're doing, you may destabalize the target app, so be careful. And be mindful of the marshalling.