1

In my MFC application i have a derived CDHtmlDialog class that opens a login screen and i need to get a url and a cookie from the server after a redirect.

I navigate to the url inside the OnInitDialog and catch the redirect inside OnNavigateComplete:

void CDMYHtmlDlg::OnNavigateComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
    BSTR *bstr = nullptr;
    this->GetDHtmlDocument(&this->m_spHtmlDoc);
    if (this->m_spHtmlDoc != nullptr)
        this->m_spHtmlDoc->get_cookie(bstr);
}

but the GetDHtmlDocument is returning E_NOINTERFACE, should i implement him? if yes how do i get the IHTMLDocument2?.

So my question is why i can't get the document and is this the right way to get a cookie?

Thank's in advance and sorry for my bad English.

Penachia
  • 389
  • 4
  • 18

1 Answers1

1

Finally figured it out.

Inside the CDHtmlDialog class the OnNavigateComplete method is responsible for assigning value to m_spHtmlDoc but since i overwritten the method no ones assign value to the document, not even the OnDocumentComplete so the simple solution is

void CDHtmlDlgPersonalizado::OnNavigateComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
    /*CALL THE PARENT METHOD*/
    CDHtmlDialog::OnNavigateComplete(pDisp, szUrl);

    /*Now GetDHtmlDocument will get the value from m_spHtmlDoc and assign to spHtmlDoc*/
    IHTMLDocument2Ptr spHtmlDoc = nullptr;
    this->GetDHtmlDocument(&spHtmlDoc);

    if (spHtmlDoc != nullptr)
    {
        BSTR bstr = ::SysAllocString(L" ");
        spHtmlDoc->get_cookie(&bstr);
    }
}
Penachia
  • 389
  • 4
  • 18