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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:53:14+00:00 2026-05-17T14:53:14+00:00

I am working with a webbrowser host on c++, I managed to sink event

  • 0

I am working with a webbrowser host on c++, I managed to sink event and I am running this void on DISPID_DOCUMENTCOMPLETE:

void DocumentComplete(LPDISPATCH pDisp, VARIANT *url)
{
    READYSTATE rState;

    iBrowser->get_ReadyState(&rState);

    if(rState == READYSTATE_COMPLETE)
    {
        HRESULT hr;
        IDispatch *pHtmlDoc = NULL;
        IHTMLDocument2 *pDocument = NULL;
        IHTMLElement *pBody = NULL;
        IHTMLElement *lpParentElm = NULL;
        BSTR bstrHTMLText;

        hr = iBrowser->get_Document(&pHtmlDoc);

        hr = pHtmlDoc->QueryInterface(IID_IHTMLDocument2, (void**)&pDocument);

        if( (FAILED(hr)) || !pDocument)
        {
            MessageBox(NULL, "QueryInterface failed", "WebBrowser", MB_OK);
        }

        hr = pDocument->get_body( &pBody );

        if( (!SUCCEEDED(hr)) || !pBody)
        {
            MessageBox(NULL, "get_body failed", "WebBrowser", MB_OK);
        }

        pBody->get_parentElement(&lpParentElm);

        lpParentElm->get_outerHTML(&bstrHTMLText);

        _bstr_t bstr_t(bstrHTMLText);

        std::string sTemp(bstr_t);

        MessageBox(NULL, sTemp.c_str(), "WebBrowser", MB_OK);
    }
}

I don’t much about c++, I built this code from watching other codes in google. Now I know I have to use ->Release, but do I have to use all these?:

    pHtmlDoc->Release();
    pDocument->Release();
    pBody->Release();
    lpParentElm->Release();
    iBrowser->Release();

Because on the examples I used to build my code it was using it only for the IHTMLElement(s).

  • 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-17T14:53:14+00:00Added an answer on May 17, 2026 at 2:53 pm

    Yes, you do have to call Release() on those pointers, otherwise objects will leak. The same goes for BSTRs.

    You’ll be much better off if you use smart pointers for that – ATL::CComPtr/ATL::CComBSTR or _com_ptr_t/_bstr_t.

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

Sidebar

Related Questions

I am working on a simple chat application using a System.Windows.Forms.WebBrowser Control to display
I'm working on a WPF app that needs to host some Flash content. The
I am working with the Webbrowser control on a windows.form application written in C#.
We're working on a wrapped WebBrowser component. We'd like to display one page (e.g.
I am working on a C# .NET application with System.Windows.Forms.WebBrowser. IE is not responding
I am currently working on a project where I am using a WebBrowser control
I am working on a project built in WPF, which includes an embedded WebBrowser.
I am working on a web crawler. I am using the Webbrowser control for
I am working on a C# application which uses an embedded WebBrowser control to
Hey everyone, I'm working an app that includes a webbrowser inside. I've done quite

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.