0

i try to make a basic browser using IWebBrowser2 on dialog based mfc

i insert an active x control into dialog, such as "microsoft web browser"

and i try "AtlAxGetControl" for getting a IWebBrowser2 pointer

but, i always get a e_fail, "res" always fail

void CIWebBrowser2Dlg::OnBnClickedButtonGo() {
CComPtr<IUnknown> punkIE;
CComQIPtr<IWebBrowser2> pWB2;
HWND hWnd;
this->GetDlgItem(IDC_EXPLORER_MAIN, &hWnd);

HRESULT res = AtlAxGetControl(hWnd, &punkIE);
if (res == S_OK) {
    pWB2 = punkIE;
    if(pWB2) {
            pWB2->GoHome();
    }
}
}

i did "AtlAxWinInit();" on initdialog

thank you for reading

plz, let me know how to handle it

Arena Son
  • 95
  • 1
  • 8
  • I think instead of doing it hard way you need to use DDX/DDV. Please read this old codeguru article as a tutorial: http://www.codeguru.com/cpp/com-tech/atl/wtl/article.php/c3609/Using-DDX-and-DDV-with-WTL.htm – cha Oct 24 '13 at 03:13
  • thank you, i did it but, i still wonder it – Arena Son Oct 24 '13 at 08:41

1 Answers1

1

Or, why not use the class wizard to generate a wrapper class for you. Then, you won't have to worry about the implementation aspects of the control.

rrirower
  • 4,338
  • 4
  • 27
  • 45
  • i solve a problem like that, but i want to know why i can not get a control using "AtlAxGetControl" on mfc. – Arena Son Oct 25 '13 at 06:11
  • Without knowing the context of the code you posted, I would guess that the hwnd you are passing is not valid. That's something you can verify by stepping through the code and using Spy++. – rrirower Oct 25 '13 at 12:40