Question

In my C++ app I'm embedding (via COM) a web browser (Internet Explorer) control (CLSID_WebBrowser).

I can display my own html in that control by using IHTMLDocument2::write() method but if the html has <img src="foo.png"> element, it's not displayed.

I assume there is a way for me to provide the data for foo.png somehow to the web control, but I can't find the right place to hook this functionality?

I need to be in full control of providing the content of foo.png, so work-arounds like using res:// protocol or saving to disk and using file:// protocol are not good enough. I just want to plug my code somehow so that when embedded CLSID_WebBrowser control sees <img src="foo.png"> in html data given with IHTMLDocument2::write() it will ask me to provide this data.

Was it helpful?

Solution

To answer my own question, the solution that finally worked for me is:

  1. register custom IInternetProtocol/IInternetProtocolInfo/ via custom IClassFactory given to IInternetSession::RegisterNameSpace(). For reasons that seem like a bug to me, it has to be a protocol already known to IE (I've chosen "its") even though it would be much better if it was my own, unique namespace.

  2. feed html data via custom IMoniker through IPersistentMoniker::Load() and make sure that IMoniker::GetDisplayName() (which is a base url according to which relative links in provided html will be resolved) starts with that protocol scheme (in my case "its://"). That way relative link "foo.png" in the html data will be its://foo.png to IE which will make urlmon call IInternetProtocol::Start() and IInternetProtocol::Read() to ask for the data for that url.

This is all rather complicated, you can look at the actual (BSD-licensed) code here: http://code.google.com/p/sumatrapdf/source/browse/trunk/src/utils/HtmlWindow.cpp

OTHER TIPS

You can embed a small webserver such as mongoose and reference those impage from there.

In mongoose, you can attach callback to specific path, thus returning images from C++ code.

We use this for our debugging tools, where each images is accessible from a web interface

The easiest solution would be a Data URI. You'd inline out the image directly with IHTMLDocument2::write().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top