IE web browser control res:// usage

2020-07-20 03:41发布

问题:

I'm using the IWebBrowser2 control in my app and I have various html files that are stored as resources in the exe. To load these up I use the "res://" protocol. The problem is that with certain versions of IE the pages no longer load up, and instead just shows "Action Canceled, Internet Explorer was unable to link to the page requested."

The pages are referenced in the .rc script like so:

stats.html HTML DISCARDABLE "res\stats.html"

The res request looks like res://C:\path\To\MyApp.exe/stats.html

This used to work just fine, at some point this behavior changed, presumably with a hot fix or something like that. Now, on my machine, it doesn't work. I have tried altering the res path to look like:

res://MyApp.exe/stats.html

that didn't work.

I then tried changing the rc script:

stats HTML DISCARDABLE "res\stats.html"

and the res path:

res://MyApp.exe/stats

Now it works! However this is really annoying to have to use this way (removing the "." and file extension from the resource name). Does anyone know if this is a bug? A feature? Why does this happen and is there another way around this?

Edit: After playing around some more I found this to work: stats.htm HTML DISCARDABLE "res\stats.html" res://MyApp.exe/stats.htm

changing the ".html" extension in the resource name to ".htm" works but I have no idea why!

回答1:

Make sure the Content Type is set correctly. Make sure that HKEY_CLASSES_ROOT.html has it's Content Type set to "text/html", otherwise strange things happen. Ditto for .htm as well.