Click here to Skip to main content
15,899,026 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ImageList, Listbox and single bitmap palette Pin
JG53_Jaguar15-Apr-08 6:27
JG53_Jaguar15-Apr-08 6:27 
QuestionHow to distinguish between VISTA and XP by using a registry key? Pin
TalSt15-Apr-08 3:12
TalSt15-Apr-08 3:12 
GeneralRe: How to distinguish between VISTA and XP by using a registry key? Pin
JudyL_MD15-Apr-08 5:27
JudyL_MD15-Apr-08 5:27 
GeneralRe: How to distinguish between VISTA and XP by using a registry key? Pin
TalSt15-Apr-08 19:28
TalSt15-Apr-08 19:28 
GeneralMFC Application in Different Resolution Pin
mehmetned15-Apr-08 3:05
mehmetned15-Apr-08 3:05 
GeneralRe: MFC Application in Different Resolution Pin
Hamid_RT15-Apr-08 3:44
Hamid_RT15-Apr-08 3:44 
GeneralRe: MFC Application in Different Resolution Pin
Iain Clarke, Warrior Programmer15-Apr-08 5:41
Iain Clarke, Warrior Programmer15-Apr-08 5:41 
QuestionWhy do IWebBrowser2::Navigate2 return E_FAIL? Pin
Johann Gerell15-Apr-08 3:01
Johann Gerell15-Apr-08 3:01 
Couldn't get any input from the "Mobile Development" board, so now I turn to the COM giants here Roll eyes | :rolleyes:

The docs on this are sparse, to say the least...

My problem: I'm trying to embed a WebBrowser object in a Windows Mobile application. I can create it and query its size and window handle, but IWebBrowser2::Navigate2 fails with E_FAIL.

Can anyone give me any hints to why it fails?

Code (yes, C++):

My host control is declared like this:
class HtmlControl : public Window // Window wraps an HWND.
{
public:
	HtmlControl(HWND window)
	: Window(window)
	, iOleObject_(NULL)
	{
		iOleSite_.host = this;
		iOleFrame_.host = this;
		CreateWebControl();
	}

	Site iOleSite_;
	Frame iOleFrame_;
	IOleObject* iOleObject_;              // The WeBrowser object.

private:
	void CreateWebControl();
};
Where Site and Frame are declared like this:
struct Site : public IOleClientSite,
              public IOleInPlaceSite
{
	HtmlControl* host;

	// IUnknown
	STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject);
	STDMETHODIMP_(ULONG) AddRef();
	STDMETHODIMP_(ULONG) Release();
	
	// IOleClientSite
	STDMETHODIMP SaveObject();
	STDMETHODIMP GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker,
	                        IMoniker** ppmk);
	STDMETHODIMP GetContainer(LPOLECONTAINER FAR* ppContainer);
	STDMETHODIMP ShowObject();
	STDMETHODIMP OnShowWindow(BOOL fShow);
	STDMETHODIMP RequestNewObjectLayout();
	
	// IOleWindow
	STDMETHODIMP GetWindow(HWND FAR* lphwnd);
	STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
	
	// IOleInPlaceSite methods
	STDMETHODIMP CanInPlaceActivate();
	STDMETHODIMP OnInPlaceActivate();
	STDMETHODIMP OnUIActivate();
	STDMETHODIMP GetWindowContext(LPOLEINPLACEFRAME FAR* lplpFrame,
	                              LPOLEINPLACEUIWINDOW FAR* lplpDoc,
	                              LPRECT lprcPosRect,
	                              LPRECT lprcClipRect,
	                              LPOLEINPLACEFRAMEINFO lpFrameInfo);
	STDMETHODIMP Scroll(SIZE scrollExtent);
	STDMETHODIMP OnUIDeactivate(BOOL fUndoable);
	STDMETHODIMP OnInPlaceDeactivate();
	STDMETHODIMP DiscardUndoState();
	STDMETHODIMP DeactivateAndUndo();
	STDMETHODIMP OnPosRectChange(LPCRECT lprcPosRect);
};

struct Frame : public IOleInPlaceFrame
{
	HtmlControl* host;

	// IUnknown
	STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject);
	STDMETHODIMP_(ULONG) AddRef();
	STDMETHODIMP_(ULONG) Release();
	
	// IOleWindow
	STDMETHODIMP GetWindow(HWND FAR* lphwnd);
	STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
	
	// IOleInPlaceUIWindow
	STDMETHODIMP GetBorder(LPRECT lprectBorder);
	STDMETHODIMP RequestBorderSpace(LPCBORDERWIDTHS pborderwidths);
	STDMETHODIMP SetBorderSpace(LPCBORDERWIDTHS pborderwidths);
	STDMETHODIMP SetActiveObject(IOleInPlaceActiveObject* pActiveObject,
	                             LPCOLESTR pszObjName);
	
	// IOleInPlaceFrame
	STDMETHODIMP InsertMenus(HMENU hmenuShared,
	                         LPOLEMENUGROUPWIDTHS lpMenuWidths);
	STDMETHODIMP SetMenu(HMENU hmenuShared, HOLEMENU holemenu,
	                     HWND hwndActiveObject);
	STDMETHODIMP RemoveMenus(HMENU hmenuShared);
	STDMETHODIMP SetStatusText(LPCOLESTR pszStatusText);
	STDMETHODIMP EnableModeless(BOOL fEnable);
	STDMETHODIMP TranslateAccelerator(LPMSG lpmsg, WORD wID);
};
The implementations of Site and Frame will be provided if needed, so that this space isn't cluttered too much.

So, the interesting function here is HtmlControl::CreateWebControl(). Let's walk it through, so that the possible strangeness of the IWebBrowser2::Navigate2 failure can be better seen.

First, an instance of the WebBrowser COM object is created and its associated IOleObject is retrieved:
IUnknown* iUnknown = NULL;
HRESULT hr = ::CoCreateInstance(CLSID_WebBrowser,
                                NULL,
                                CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
                                IID_IUnknown,
                                (void*)(&iUnknown));
VERIFY(SUCCEEDED(hr));

hr = iUnknown->QueryInterface(IID_IOleObject, (void*)(&iOleObject_));
VERIFY(SUCCEEDED(hr));
These operations were all successful in the sense that hr == S_OK.

After getting the WebControl object, I want to show/activate it using our IOleClientSite implementation:
hr = iOleObject_->SetClientSite(&iOleSite_);
VERIFY(SUCCEEDED(hr));

const RECT rect = GetClientRect();
hr = iOleObject_->DoVerb(OLEIVERB_SHOW, NULL, &iOleSite_, 0, GetHwnd(), &rect);
VERIFY(SUCCEEDED(hr));
These operations were also successful in the sense that hr == S_OK. However, the end result (the IWebBrowser2::Navigate2 failure) occurs also if OLEIVERB_SHOW is changed to OLEIVERB_UIACTIVATE or OLEIVERB_INPLACEACTIVATE.

Next, I dig the IWebBrowser2 out of the WebControl object and checks if the browser HWND is sane:
IWebBrowser2* iWebBrowser = NULL;
hr = iOleObject_->QueryInterface(IID_IWebBrowser2, (void**)&iWebBrowser);
VERIFY(SUCCEEDED(hr));

// Get browser HWND, method	1.
HWND hwndBrowser = NULL;
hr = iWebBrowser->get_HWND((long*)&hwndBrowser);
VERIFY(SUCCEEDED(hr));
VERIFY(hwndBrowser != NULL);
VERIFY(::GetParent(hwndBrowser) == GetHwnd());

// Get browser HWND, method	2.
IOleWindow* iOleWindow = NULL;
hr = iOleObject_->QueryInterface(IID_IOleWindow, (void*)(&iOleWindow));
VERIFY(SUCCEEDED(hr));

hwndBrowser = NULL;
hr = iOleWindow->GetWindow(&hwndBrowser);
VERIFY(hwndBrowser != NULL);
VERIFY(::GetParent(hwndBrowser) == GetHwnd());
Again, these operations were successful in the sense that hr == S_OK. Also, the browser HWND is equal in both method 1 and 2 and its parent is indeed our host control. I see this as some kind of indication that something works.

But... the thing I need doesn't work; the precious IWebBrowser2::Navigate2:
VARIANT vURL;
vURL.vt = VT_BSTR;
vURL.bstrVal = ::SysAllocString(L"about:blank");

VARIANT vEmpty;
vEmpty.vt = VT_EMPTY;

hr = iWebBrowser->Navigate2(&vURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);
VERIFY(SUCCEEDED(hr));
Now I get hr == E_FAIL.

I cannot really see the problem, since everything up to this point worked successfully, and the last call seems trivial.

Is anyone still around all the way down here with some guess as to what might be going on?

Thanks for any input!

--
Time you enjoy wasting is not wasted time - Bertrand Russel

AnswerRe: Why do IWebBrowser2::Navigate2 return E_FAIL? Pin
Jim Crafton15-Apr-08 8:49
Jim Crafton15-Apr-08 8:49 
AnswerRe: Why do IWebBrowser2::Navigate2 return E_FAIL? Pin
Jim Crafton15-Apr-08 8:56
Jim Crafton15-Apr-08 8:56 
Questionhow can i create icon dynamically in system tray .. Pin
vasu_sri15-Apr-08 2:54
vasu_sri15-Apr-08 2:54 
AnswerRe: how can i create icon dynamically in system tray .. Pin
enhzflep15-Apr-08 3:18
enhzflep15-Apr-08 3:18 
GeneralRe: how can i create icon dynamically in system tray .. Pin
Iain Clarke, Warrior Programmer15-Apr-08 5:46
Iain Clarke, Warrior Programmer15-Apr-08 5:46 
GeneralRe: how can i create icon dynamically in system tray .. Pin
enhzflep15-Apr-08 5:59
enhzflep15-Apr-08 5:59 
Generaldeleting folder containting files Pin
neha.agarwal2715-Apr-08 1:52
neha.agarwal2715-Apr-08 1:52 
AnswerRe: deleting folder containting files Pin
Shirani15-Apr-08 1:59
Shirani15-Apr-08 1:59 
GeneralRe: deleting folder containting files Pin
neha.agarwal2715-Apr-08 2:04
neha.agarwal2715-Apr-08 2:04 
GeneralRe: deleting folder containting files Pin
David Crow15-Apr-08 7:35
David Crow15-Apr-08 7:35 
GeneralRe: deleting folder containting files Pin
kakan15-Apr-08 2:04
professionalkakan15-Apr-08 2:04 
GeneralRe: deleting folder containting files Pin
Hamid_RT15-Apr-08 2:06
Hamid_RT15-Apr-08 2:06 
GeneralRe: deleting folder containting files Pin
toxcct15-Apr-08 2:06
toxcct15-Apr-08 2:06 
GeneralRe: deleting folder containting files Pin
platso_58815-Oct-12 23:18
platso_58815-Oct-12 23:18 
Questionprocesses and handles Pin
YS888815-Apr-08 1:36
YS888815-Apr-08 1:36 
GeneralRe: processes and handles Pin
Hamid_RT15-Apr-08 1:52
Hamid_RT15-Apr-08 1:52 
GeneralRe: processes and handles Pin
YS888815-Apr-08 2:28
YS888815-Apr-08 2:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.