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 309039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:42:19+00:00 2026-05-12T07:42:19+00:00

so far, I’ve successfully used the following function to retrieve the IWebBrowser2 pointer to

  • 0

so far, I’ve successfully used the following function to retrieve the IWebBrowser2 pointer to a running Internet Explorer instance, given it’s PID.

static SHDocVw::IWebBrowser2Ptr findBrowserByPID( DWORD pid )
{
    SHDocVw::IShellWindowsPtr ptr;
    ptr.CreateInstance(__uuidof(SHDocVw::ShellWindows));
    if ( ptr == NULL ) {
        return 0;
    }

    // number of shell windows
    const long nCount = ptr->GetCount();

    // iterate over all shell windows
    for (long i = 0; i < nCount; ++i) {
        // get interface to item no i
        _variant_t va(i, VT_I4);
        IDispatchPtr spDisp = ptr->Item(va);

        SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
        if (spBrowser != NULL) {
            // if there's a document we know this is an IE object
            // rather than a Windows Explorer instance
            HWND browserWindow;
            try {
                browserWindow = (HWND)spBrowser->GetHWND();
            } catch ( const _com_error &e ) {
                // in case ->GetHWND() fails
                continue;
            }

            DWORD browserPID;
            GetWindowThreadProcessId( browserWindow, &browserPID );
            if ( browserPID == pid ) {
                return spBrowser;
            }
        }
    }
    return 0;
}

What I do is to launch an explorer.exe process via CreateProcess and then use the above function to retrieve the IWebBrowser2Ptr to it (so that I can fiddle with the browser).

Unfortunately, this doesn’t seem to work with Internet Explorer 8 anymore, since IE8 seems to reuse processes – at least to some degree. For two code sequences like:

PROCESS_INFORMATION pi;
// ...

if ( CreateProcess( ..., &pi ) ) {
    // Wait a bit to give the browser a change to show its window
    // ...

    IWebBrowser2 *pWebBrowser = findBrowserByPID( pi.dwProcessId );
}

The first run of this code works fine, the second one never manages to retrieve the pWebBrowser window.

After a bit of debugging, it was revealed that the findBrowserByPID function does find lots of browser windows (and it finds more after starting a second browser instance), but none of them belong to the newly started process. It seems that all windows belong to the first IE process which was started.

Does anybody know an alternative way to get the IWebBrowser2 pointer to some IE8 instance? Or is there maybe a way to disable this apparent ‘reuse’ of processes with IE8?

  • 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-12T07:42:20+00:00Added an answer on May 12, 2026 at 7:42 am

    If you’re launching the IE Process yourself, don’t use CreateProcess– instead, use CoCreateInstance. That will return you an object for which you can query for IWebBrowser2, which you can use at will. The one complexity is that if the navigation crosses integrity levels (Vista+) the pointer becomes invalid. To address that problem, sync the NewProcess event, which will allow you to detect this condition.

    See some more info here: http://msdn.microsoft.com/en-us/library/aa752084%28VS.85%29.aspx

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

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you tried using Session instead. It will be better… May 12, 2026 at 4:25 pm
  • Editorial Team
    Editorial Team added an answer For quick EmpID, see following: string xml = @"<div class=""details""><a… May 12, 2026 at 4:25 pm
  • Editorial Team
    Editorial Team added an answer Parse values, use std::mktime function to get time_t and now… May 12, 2026 at 4:25 pm

Related Questions

this is what i have right now Drawing an RSS feed into the php,
So far, I've only been passing javascript strings to my web methods, which get
So far, I've had great success using PyAMF to communicate between my Flex front-end
so far, I've successfully used the following function to retrieve the IWebBrowser2 pointer to
So far I have done this, I am not sure whether this is right

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.