Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:05:41+00:00 2026-05-28T14:05:41+00:00

I have an application (written in C++ with MFC, but I don’t think that

  • 0

I have an application (written in C++ with MFC, but I don’t think that that’s particularly relevant) that embeds the Internet Explorer ActiveX WebBrowser control for the purpose of showing some HTML pages. One requirement has always been to use the application’s font name and size settings as the default settings for the HTML, rather than Internet Exporer’s defaults.

To achieve this, the application implements the IDocHostUIHandler2 COM interface, which it passes to the WebBrowser control. This causes the control to call the application’s implementation of GetOptionKeyPath, which lets the application set the registry location that the WebBrowser control gets its settings from. Armed with Sysinternals’ tools to see which keys IE uses to find the font name and size, this has been sufficient to do what I need.

However, the appeareance of Internet Explorer 9 has come as a nasty surprise: on all machines that I’ve tested with that have IE9 installed, the WebBrowser control uses its own settings, ignoring the registry location from the application. Testing with a debugger shows that the WebBrowser control never calls the provided GetOptionKeyPath.

A bit more experimentation shows that the IE9 WebBrowser control is calling the similar (but not identical) GetOverrideKeyPath method: this allegedly provides a way to override IE settings, while falling back to IE’s actual settings if nothing is found in the relevant part of the registry. Unfortunately this has two problems: 1) It’s not quite what I want, and 2) IE9 doesn’t always check under the GetOverrideKeyPath registry location before going to the IE default registry settings.

Looking at the GetOptionKeyPath MSDN page there are a few complaints along similar lines, but no solutions. Has anyone found a clean way to persuade the WebBrowser control to revert to the pre-IE9 behaviour of actually calling GetOptionKeyPath as documented?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:05:42+00:00Added an answer on May 28, 2026 at 2:05 pm

    I’ve come up with a hack to solve this problem, but I should warn you: it’s not pretty. Stop reading now if you’ve easily offended …

    Since there seems to be no way of making IE9 use the IDocHostUIHandler::GetOptionKeyPath() method, I used SysInternals’ tools to see which IE9 DLLs accessed the relevant parts of the registry to load the IE9 settings. This revealed the only culprits as “mshtml.dll” and “iertutil.dll”, both of which call RegOpenKeyExW().

    The plan was then to load these DLLs before initializing the WebBrowser control, and patch them so that calls are redirected to my code, where I can lie about what registry key I’ve opened, using dbghelp.dll. So, to start, before initializing the WebBrowser control:

    if (theApp.GetIEVersion() >= 9.0)
    {
      HMODULE advadi = ::LoadLibrary("advapi32.dll");
      HMODULE mshtml = ::LoadLibrary("mshtml.dll");
      HookApiFunction(mshtml,advadi,"advapi32.dll","RegOpenKeyExW",(PROC)HookRegOpenKeyExW);
      HMODULE iertutil = ::LoadLibrary("iertutil.dll");
      HookApiFunction(iertutil,advadi,"advapi32.dll","RegOpenKeyExW",(PROC)HookRegOpenKeyExW);
    }
    

    And now, the code that does the evil work of scanning the DLLs import address tables, and patching the requested function (error handling omitted to keep the code size down):

    void HookApiFunction(HMODULE callingDll, HMODULE calledDll, const char* calledDllName, const char* functionName, PROC newFunction)
    {
      // Get the pointer to the 'real' function
      PROC realFunction = ::GetProcAddress(calledDll,functionName);
    
      // Get the import section of the DLL, using dbghelp.dll's ImageDirectoryEntryToData()
      ULONG sz;
      PIMAGE_IMPORT_DESCRIPTOR import = (PIMAGE_IMPORT_DESCRIPTOR)
        ImageDirectoryEntryToData(callingDll,TRUE,IMAGE_DIRECTORY_ENTRY_IMPORT,&sz);
    
      // Find the import section matching the named DLL
      while (import->Name)
      {
        PSTR dllName = (PSTR)((PBYTE)callingDll + import->Name);
        {
          if (stricmp(dllName,calledDllName) == 0)
           break;
        }
        import++;
      }
      if (import->Name == NULL)
        return;
    
      // Scan the IAT for this DLL
      PIMAGE_THUNK_DATA thunk = (PIMAGE_THUNK_DATA)((PBYTE)callingDll + import->FirstThunk);
      while (thunk->u1.Function)
      {
        PROC* function = (PROC*)&(thunk->u1.Function);
        if (*function == realFunction)
        {
          // Make the function pointer writable and hook the function
          MEMORY_BASIC_INFORMATION mbi;
          ::VirtualQuery(function,&mbi,sizeof mbi);
          if (::VirtualProtect(mbi.BaseAddress,mbi.RegionSize,PAGE_READWRITE,&mbi.Protect))
          {
            *function = newFunction;
            DWORD protect;
            ::VirtualProtect(mbi.BaseAddress,mbi.RegionSize,mbi.Protect,&protect);
            return;
          }
        }
        thunk++;
      }
    

    Finally, the function that I have patched the DLLs to call in my code, in place of RegOpenKeyExW():

    LONG WINAPI HookRegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
    {
      static const wchar_t* ieKey = L"Software\\Microsoft\\Internet Explorer";
    
      // Never redirect any of the FeatureControl settings
      if (wcsstr(lpSubKey,L"FeatureControl") != NULL)
        return ::RegOpenKeyExW(hKey,lpSubKey,ulOptions,samDesired,phkResult);
    
      if (wcsnicmp(lpSubKey,ieKey,wcslen(ieKey)) == 0)
      {
        // Redirect the IE settings to our registry key
        CStringW newSubKey(m_registryPath);
        newSubKey.Append(lpSubKey+wcslen(ieKey));
        return ::RegOpenKeyExW(hKey,newSubKey,ulOptions,samDesired,phkResult);
     }
     else
       return ::RegOpenKeyExW(hKey,lpSubKey,ulOptions,samDesired,phkResult);
    }
    

    Amazingly enough, this horrible hack actually works. But please, Microsoft, if you’re listening, please fix this properly in IE10.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SDI application written in MFC. The frame is divided into 1
I have an application written using C++ Builder 5 that uses the TDocument class.
I have an application written in C# that invokes some C code as well.
I have a Windows mobile 4.0 application, written using EVC++ 4.0 SP4 with MFC,
We have a windows MFC app that is written against an access database on
I have application written in C#. Memory usage shows that there is a memory
I have a WPF application implemented using the MVVM framework that uses an ActiveX
I have application written in Java that is using EJB3 + Toplink. I'm using
I have an application written in C# that uses Outlook Interop to open a
We have an application written in C# .NET that is currently used in production

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.