WebBrowser Control using OLE Automation

Hi :

I want to control Internet Explorer from my application - run an instance, position on screen, navigate to various URL's etc - basic stuff.

Without including the webbrowser control within my application (pure C, no MFC, no ATL, not generated using any wizard) what is the best way to do this?

Here's what I came up with - do a clsidfromprogid to get internetexplorer clsid, use cocreateinstance to create an instance of it, queryinterface for Iwebbrowser2, and use that to call navigate etc.

This approach does not seem to work. Browser window comes up and gets positioned, but further calls to navigate dont seem to work.

Also, it takes a while for the browser window to come up. Looks really bad from the user point of view.

Any ideas and is there a better/faster way to do this?

Rima Parikh.
Who is Participating?
chensuConnect With a Mentor Commented:
The following is the C++ code. Let me know if you have trouble converting it to C.

IWebBrowser2 *pwb;
HRESULT hr = ::CoCreateInstance(CLSID_InternetExplorer,
                                (void **)&pwb);
if (SUCCEEDED(hr))
    _variant_t vtURL(_T("http://www.experts-exchange.com"));
    _variant_t vtNoArg;
    pwb->Navigate2(&vtURL, &vtNoArg, &vtNoArg, &vtNoArg, &vtNoArg);
rparikhAuthor Commented:
Thanks, that's faster than my approach and it worked.
All Courses

From novice to tech pro — start learning today.