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

  • Home
  • SEARCH
  • 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 4045580
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:26:55+00:00 2026-05-20T13:26:55+00:00

I am working on a browser automation framework , which automates Internet Explorer, as

  • 0

I am working on a browser automation framework, which automates Internet Explorer, as well as other browsers. I am running into an intermittent problem when attempting to launch IE. The framework launches IE using the IELaunchURL API if it is present, and uses CreateProcess if not. The code to obtain the IWebBrowser2 interface is as follows:

// hwndBrowser is obtained by calling ::EnumWindows() with a function that
// compares the process ID of the window handle to the known process ID of
// the IE instance.
CComPtr<IHTMLDocument2> document;
LRESULT result;
::SendMessageTimeout(hwndBrowser,
                     WM_HTML_GETOBJECT,
                     0L,
                     0L,
                     SMTO_ABORTIFHUNG,
                     1000,
                     (PDWORD_PTR)&result);

// oleacc_instance_handle is obtained from ::LoadLibrary("oleacc.dll")
LPFNOBJECTFROMLRESULT object_pointer =  reinterpret_cast<LPFNOBJECTFROMLRESULT>(
         ::GetProcAddress(oleacc_instance_handle, "ObjectFromLresult"));

if (object_pointer != NULL) {
    HRESULT hr = (*object_pointer)(result,
                                   IID_IHTMLDocument2,
                                   0,
                                   reinterpret_cast<void **>(&document));

    if (SUCCEEDED(hr)) {
        CComPtr<IHTMLWindow2> window;
        hr = document->get_parentWindow(&window);

        if (SUCCEEDED(hr)) {
            // http://support.microsoft.com/kb/257717
            CComQIPtr<IServiceProvider> provider(window);

            if (provider) {
                CComPtr<IServiceProvider> child_provider;
                hr = provider->QueryService(SID_STopLevelBrowser, 
                                            IID_IServiceProvider,
                                            reinterpret_cast<void **>(&child_provider));

                if (SUCCEEDED(hr)) {
                    IWebBrowser2* browser;
                    hr = child_provider->QueryService(SID_SWebBrowserApp,
                                                      IID_IWebBrowser2,
                                                      reinterpret_cast<void **>(&browser));
                    if (SUCCEEDED(hr)) {
                        // The IWebBrowser2 pointer is passed back to the caller.
                        // process_window_info->pBrowser = browser;
                    }
                }
            }
        }
    }
}

Now for the problem: It seems that we can always successfully retrieve the IHTMLDocument2 object. However, when we attempt to call get_parentWindow(), we sometimes receive a “class not registered” result (0x80040154 REGDB_E_CLASSNOTREG), most often when launching a new instance of IE after closing a previous one. We can get the IWebBrowser2 interface by omitting the call to get_parentWindow() and simply calling QueryService directly on the document, but we will receive this error further down the line when we try to manipulate parts of the document. What could cause the get_parentWindow() call to fail?

Note that the entirety of the code can be found in context here.

  • 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-20T13:26:56+00:00Added an answer on May 20, 2026 at 1:26 pm

    The problem was in the use of threading in the application. We were not properly waiting for a thread to terminate before launching a new instance of IE.

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

Sidebar

Related Questions

I'm working on an ASP.NET website which targets desktop browsers. We want to enable
I need to have a working web browser in a fullscreen Direct3D application. For
I am working on an in-browser editor within a textarea . I have started
I run a browser based game at www.darknovagames.com. Recently, I've been working on reformatting
When you are working on a new website, what combinations of browsers and operating
I am working on a project for a client which needs an automatic login
I am working on a browser plugin that takes the URL of the current
I'm working on a console based file browser for Windows in C++ and am
I am working on a web browser with c++ using IWebBrowser2. Declared on the
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch

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.