Click here to Skip to main content
15,892,746 members
Home / Discussions / Mobile
   

Mobile

 
GeneralRe: Creating a service for Smartphone. Pin
Giannakakis Kostas18-Apr-08 9:43
professionalGiannakakis Kostas18-Apr-08 9:43 
GeneralLaunch/Call an Application/Function on the keypress and hold event Pin
Parasmani Swamy16-Apr-08 19:15
Parasmani Swamy16-Apr-08 19:15 
GeneralRe: Launch/Call an Application/Function on the keypress and hold event Pin
Ravenet21-Apr-08 2:28
Ravenet21-Apr-08 2:28 
GeneralRe: Launch/Call an Application/Function on the keypress and hold event Pin
Parasmani Swamy28-Apr-08 23:24
Parasmani Swamy28-Apr-08 23:24 
GeneralConsuming web service from mobile app Pin
CodingYoshi16-Apr-08 9:12
CodingYoshi16-Apr-08 9:12 
GeneralRe: Consuming web service from mobile app Pin
Ravenet16-Apr-08 15:57
Ravenet16-Apr-08 15:57 
Questionproblem in windows os function calls while plug out the storage card [modified] Pin
anish.chandran16-Apr-08 6:22
anish.chandran16-Apr-08 6:22 
QuestionWhy do IWebBrowser2::Navigate2 return E_FAIL? Pin
Johann Gerell14-Apr-08 23:48
Johann Gerell14-Apr-08 23:48 
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

QuestionHow to make a floating window Pin
Qilinzhi14-Apr-08 22:27
Qilinzhi14-Apr-08 22:27 
GeneralNetworkstream receiving same data twice [modified] Pin
evdsande14-Apr-08 10:29
evdsande14-Apr-08 10:29 
AnswerRe: Networkstream receiving same data twice Pin
Arjun Marwaha24-Apr-08 2:29
Arjun Marwaha24-Apr-08 2:29 
QuestionHow to catch usb event Pin
haolan13-Apr-08 22:04
haolan13-Apr-08 22:04 
AnswerRe: How to catch usb event Pin
Ravenet16-Apr-08 16:01
Ravenet16-Apr-08 16:01 
GeneralRe: How to catch usb event Pin
haolan21-Apr-08 1:31
haolan21-Apr-08 1:31 
GeneralRe: How to catch usb event Pin
Ravenet21-Apr-08 2:03
Ravenet21-Apr-08 2:03 
GeneralRe: How to catch usb event Pin
haolan21-Apr-08 2:11
haolan21-Apr-08 2:11 
GeneralRe: How to catch usb event Pin
Ravenet21-Apr-08 2:16
Ravenet21-Apr-08 2:16 
QuestionHow can I monitoring dial and how to Disconnect for POCKET PC Pin
smsm365011-Apr-08 3:36
smsm365011-Apr-08 3:36 
QuestionHow to launch pword.exe in .NET 2005 'Smart Device project' Pin
tony_Udz11-Apr-08 0:14
tony_Udz11-Apr-08 0:14 
GeneralRe: How to launch pword.exe in .NET 2005 'Smart Device project' Pin
Arjun Marwaha15-Apr-08 21:32
Arjun Marwaha15-Apr-08 21:32 
QuestionHow to Program with Wireless Sensors Pin
csnovice9-Apr-08 18:40
csnovice9-Apr-08 18:40 
QuestionIs my C.F. 2.0 crazy?.....Or not? Pin
Hurricane30009-Apr-08 10:47
Hurricane30009-Apr-08 10:47 
AnswerRe: Is my C.F. 2.0 crazy?.....Or not? Pin
Mitch F.9-Apr-08 19:35
Mitch F.9-Apr-08 19:35 
GeneralRe: Is my C.F. 2.0 crazy?.....Or not? [modified] Pin
Hurricane300010-Apr-08 3:56
Hurricane300010-Apr-08 3:56 
GeneralRe:Resolved! [modified] Pin
Hurricane300010-Apr-08 6:34
Hurricane300010-Apr-08 6:34 

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.