|
Prev: DeviceIoControl (Drive serial name OFFSET -> CHAR) [C++ | WINAPI]
Next: How to implement a "resident" application
From: moonfacell on 7 May 2008 05:22 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 :)
From: Christian ASTOR on 7 May 2008 08:26 moonfacell(a)gmail.com wrote: > > hr = pBrowser->Navigate(ole_url, NULL, NULL, NULL, NULL); VARIANT varEmpty; VariantInit(&varEmpty); hr = pBrowser->Navigate(ole_url, &varEmpty, &varEmpty, &varEmpty, &varEmpty);
From: Sebastian G. on 7 May 2008 09:57
moonfacell(a)gmail.com wrote: > 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... 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? |