IWebBrowser: How to specify the encoding when loading html from a stream?

Posted by Ian Boyd on Stack Overflow See other posts from Stack Overflow or by Ian Boyd
Published on 2010-04-06T15:09:56Z Indexed on 2010/04/06 15:13 UTC
Read the original article Hit count: 345

Filed under:
|
|
|

Using the concepts from the sample code provided by Microsoft for loading HTML content into an IWebBrowser from an IStream using the web browser's IPersistStreamInit interface:

HRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream)
{
   [snip]
}

How can one specify the encoding of the html inside the IStream? The IStream will contain a series of bytes, but the problem is what do those bytes represent? They could, for example, contain bytes where:

  • each byte represents a character from the current Windows code-page (e.g. 1252)
  • each byte could represent a character from the ISO-8859-1 character set
  • the bytes could represent UTF-8 encoded characters
  • every 2 bytes could represent a character, using UTF-16 encoding

In my particular case, i am providing the IWebBrowser an IStream that contains a series of double-bytes characters (UTF-16), but the browser (incorrectly) believes that UTF-8 encoding is in effect. This results in garbled characters.

© Stack Overflow or respective owner

Related posts about iwebbrowser2

Related posts about encoding