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 