Tech Support > Microsoft Windows > Development Resources > IWebBrowser2->Navigate() Failure...
IWebBrowser2->Navigate() Failure...
Posted by moonfacell@gmail.com on May 7th, 2008


Hi guys,
I use IWebBrowser2 in a console application WITHOUT MFC, but met a
problem: I can start the IE, but Navigate() always return failure...

My code:
// browser.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "mshtml.h"
#include <Exdisp.h> //for IWebBrowser2
#include <iostream>
#include <assert.h>
using namespace std;
void TestIEControl()
{
CoInitialize(NULL);

CString progid(L"InternetExplorer.Application.1");
BSTR ole_progid = progid.AllocSysString();

CLSID clsid;
CLSIDFromProgID(ole_progid,&clsid);
::SysFreeString(ole_progid);

IWebBrowser2* pBrowser;

CoCreateInstance(
clsid,
NULL,
CLSCTX_LOCAL_SERVER,
IID_IWebBrowser2,
(void**)&pBrowser
);

CString url(L"www.google.com");
BSTR ole_url = url.AllocSysString();

HRESULT hr = pBrowser->put_Visible(TRUE);
assert(SUCCEED(hr));

hr = pBrowser->Navigate(ole_url, NULL, NULL, NULL, NULL);

printf("%x\n", hr);
if(hr == S_OK)
{
cout << "Navigate SUCCEEDED" << endl;
}
else if(hr == E_INVALIDARG)
{
cout << "Navigate E_INVALIDARG !" << endl;
}
else if(hr == E_OUTOFMEMORY)
{
cout << "Navigate E_OUTOFMEMORY !" << endl;
}
else
{
cout << "Other Error..." << endl;
}

//pBrowser->
::SysFreeString(ole_url);
pBrowser->Release();

CoUninitialize();
}

int _tmain(int argc, _TCHAR* argv[])
{
TestIEControl();
return 0;
}

Any help is greatly appreciated! Thanks

Posted by Christian ASTOR on May 7th, 2008


moonfacell@gmail.com wrote:


VARIANT varEmpty;
VariantInit(&varEmpty);
hr = pBrowser->Navigate(ole_url, &varEmpty, &varEmpty, &varEmpty,
&varEmpty);

Posted by Sebastian G. on May 7th, 2008


moonfacell@gmail.com wrote:


As it should. Any sane configuration has set IE's proxy to
localhost:discard. Maybe you should use ShellExecuteEx to launch the default
browser instead?

Posted by moonfacell@gmail.com on May 8th, 2008


On 5ÔÂ7ÈÕ, ÏÂÎç8ʱ26·Ö, Christian ASTOR <casto...@club-internet.fr> wrote:
Yes. I modified here and it works!

Thank you


Similar Posts