I'm trying to make my MFC application access a login screen from a website (like Spotify does), the idea is that after the user log in the site will redirect him to another page with a cookie.
I'm using a derived CDHtmlDialog class and "getting" the redirect inside the OnNavigateComplete method but the IHtmlDocument2Ptr (m_spHtmlDoc)is always null.
void CDHtmlDlgPersonalizado::OnNavigateComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
this->GetDHtmlDocument(&this->m_spHtmlDoc);
if (this->m_spHtmlDoc != nullptr)
this->m_spHtmlDoc->get_cookie(bstr);
}
How can i get a cookie from my c++ code?
EDIT: The GetDHtmlDocument returns E_NOINTERFACE inside the OnNavigateComplete and OnDocumentComplete. The navigation to the login screen is made inside the OnInitDialog method:
BOOL CDHtmlDlgPersonalizado::OnInitDialog()
{
CDHtmlDialog::OnInitDialog();
CString str(_T("http://www.MyLoginScreen.com/"));
this->Navigate(str);
return TRUE;
}
This code is called inside a CDialogEx derived class:
BOOL CDlgMsgBoxHtml::OnInitDialog()
{
CDialogEx::OnInitDialog();
VERIFY(this->m_HtmlCtrl.SubclassDlgItem(IDC_HTML, this));
/*m_HtmlCtrl is the object to the CDHtmlDialog derived class*/
this->m_HtmlCtrl.OnInitDialog();
/*I also tried calling the navigate here*/
//CString str3(_T("http://www.MyLoginScreen.com/"));
//this->m_HtmlCtrl.Navigate(str3);
/*But got the same results*/
//IHTMLDocument2Ptr spHtmlDoc = nullptr;
//this->m_HtmlCtrl.GetDHtmlDocument(&spHtmlDoc);
return TRUE;
}
Thanks in advance and sorry for my bad English.