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?

Thanks,
Rima Parikh.
rparikhAsked:
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.


::CoInitialize(NULL);
IWebBrowser2 *pwb;
HRESULT hr = ::CoCreateInstance(CLSID_InternetExplorer,
                                NULL,
                                CLSCTX_LOCAL_SERVER,
                                IID_IWebBrowser2,
                                (void **)&pwb);
if (SUCCEEDED(hr))
{
    pwb->put_Visible(VARIANT_TRUE);
    _variant_t vtURL(_T("http://www.experts-exchange.com"));
    _variant_t vtNoArg;
    pwb->Navigate2(&vtURL, &vtNoArg, &vtNoArg, &vtNoArg, &vtNoArg);
    ::Sleep(10000);
    pwb->Quit();
    pwb->Release();
}
::CoUninitialize();
0
 
rparikhAuthor Commented:
Thanks, that's faster than my approach and it worked.
0
All Courses

From novice to tech pro — start learning today.