Question

This is somewhat a duplicate of this question, but that question has no (valid) answer and is 1.5 years old so asking my own with hopes people have more info now.

If you are using multiple instances of a WebBrowser control, MSHTML, IHTMLDocument, or whatever... from inside the APP instance, mostly IInternetProtocol::Start, is there a way to know which instance is loading the resource? Or is there a way to use a different APP for each instance of the control, maybe by providing one via IDocHostUIHandler or ICustomDoc or otherwise? I'm currently using IInternetSession::RegisterNameSpace to make it process wide.

Optional reading below, don't feel you need to read it unless above isn't clear.

I'm working on a legacy (Win32 C++) email client that uses the MS ActiveX WebBrowser control (MSHTML or other names it goes by) to display HTML emails. It was saving everything to temp files, updating the cid: URLs, and then having the control load that. Now I want to do it the correct way, using APP. I've got it all working with some test code that just uses static variables/globals and loads one email.

My problem now is, the app might have several instances of the control all loading different emails (and other stuff) at the same time... not really multiple threads so much, just the asynchronous nature of the control. I can give each instance of the control a unique URL to load the email, say, cid:email-GUID, and then in my APP code I can use that URL to know which email to load. However, when it comes to loading any content inside the email, like attached images using src="cid:", those will not always be unique so I will not always know which image it is, for which email. I'd like to avoid having to modify the URLs of the HTML before displaying it (I'm doing that now for the temp file thing, but want to do it a better way).

IInternetBindInfo::GetBindString can return the referrer, BINDSTRING_XDR_ORIGIN, or the root URL, BINDSTRING_ROOTDOC_URL, but those require newer versions of IE and my legacy app must support older XP installs that might even have IE6 or IE7, so I'd rather not use these.

Tagged as TWebBrowser because that is actually what I'm using (Borland Builder 6 C++), but don't need answers specific to that platform.

Was it helpful?

Solution

As the Asynchronous Pluggable Protocol Handler us very low level, you cannot attach handlers individually to different rendering controls.

Here is a way to get the referrer:

  1. Obtain BINDSTRING_HEADERS
  2. Extract the referrer by parsing the line Referer: http://....
  3. See also How can I add an extra http header using IHTTPNegotiate?

Here is another crazy way:

  1. Create another Asynchronous Pluggable Protocol Handler by calling RegisterMimeFilter.
  2. Monitor text/plain and text/html
  3. Scan the incoming email source (content comes incrementally) and parse store all image links in a dictionary
  4. In NameSpaceHandler you can use this dictionary to find the reference of any image resources.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top