1

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.

Penachia
  • 389
  • 4
  • 18
  • Is [this](http://stackoverflow.com/questions/42437697/get-cookie-from-cdhtmldialog) the same question? – Steeve Mar 03 '17 at 12:30
  • @Steeve I thought this one was more broad, and that one didn't have any answers or views – Penachia Mar 03 '17 at 12:38
  • If a question doesn't have views or answers, it's often, because it is a poor question (both this and your other question certainly classify for that). Neither justifies re-asking the same question. If you want to provide additional information, [edit](http://stackoverflow.com/posts/42437697/edit) your question. Voting to close as duplicate. – IInspectable Mar 03 '17 at 12:59
  • @LiquidPenguin Do I understand it correctly that the problem at this point is not the cookie but that the `GetDHtmlDocument` returns NULL? – Steeve Mar 03 '17 at 13:06
  • @LiquidPenguin Can you check the return value of `GetDHtmlDocument`? The [doc](https://msdn.microsoft.com/en-us/library/8bed8k60.aspx#cdhtmldialog__getdhtmldocument) says it has a `HRESULT` return value that should indicate any error. – Steeve Mar 03 '17 at 13:17
  • @Steeve it returns E_NOINTERFACE – Penachia Mar 03 '17 at 13:18
  • @IInspectable thanks for your comment, i'll try to improve my questions in the future, Can i close the other question instead? this one is more "alive" – Penachia Mar 03 '17 at 13:20
  • A question being *"alive"* (what is that anyways?) is not a good measure of whether it should be closed or not. At least your other question contains helpful diagnostics (like the error code) which is completely missing from this question. – IInspectable Mar 03 '17 at 13:26
  • @LiquidPenguin Can maybe the problem be that the document is not loaded yet? As in [this](http://stackoverflow.com/questions/5853607/how-to-use-getdhtmldocument-in-mfc-programming) answer, maybe you should override `OnDocumentComplete` instead of `OnNavigateComplete`? – Steeve Mar 03 '17 at 13:31
  • @Steeve yes i tried that but got the same results – Penachia Mar 03 '17 at 13:53
  • @LiquidPenguin Does it work without the redirection? – Steeve Mar 03 '17 at 13:55
  • @Steeve sorry i didnt understand what do you mean. I can show the login screen and see the redirect after the user login but i cant get the document ( and the cookie). – Penachia Mar 03 '17 at 13:58
  • @LiquidPenguin That beats me, can you maybe edit and include more code and details in the question please? – Steeve Mar 03 '17 at 14:04

0 Answers0