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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rparikhAuthor Commented:
Thanks, that's faster than my approach and it worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.