Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reusing the web browser control

I have a pure Win32 application (no MFC, etc.) to which I want to add a web browser control in a window. I know the basics of COM and can create a COM object for the browser using

 hr = CoCreateInstance(
    CLSID_WebBrowser,
    NULL,
    CLSCTX_INPROC,
    IID_IWebBrowser2,
    (void**) &pWebBrowser);

However, apparently one needs to call SetClientSite, passing an IOleClientSite*. How do I obtain such an interface? This example implements its own browser class, which provides the interface by deriving from it and implementing it (here). I tried to go along that path, but in order to instantiate the browser class, I would have to register it (no?). This seems awfully complicated - I just want to use an existing COM object, not implement and register my own. What am I missing?

Assuming I do implement my own ClientSite class as part of my application, is it possible to not register it, and just instantiate it by calling new ClientSite (and then fetch the interface as using QueryInterface)? Will this work, or is it mandatory to call CoCreateInstance?

like image 765
Dabbler Avatar asked Sep 28 '12 21:09

Dabbler


1 Answers

There is an example on CodeGuru and another on CodeProject which contains the simplest implementation for hosting a web browser control implemented in pure C. You do have to implement your own IOleClientSite, but it is one of the easier classes to implement. Yes, it is mandatory to call CoCreateInstance or OleCreate to create the instance of the web browser control.

http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4379/Display-a-Web-Page-in-a-Plain-C-Win32-Application.htm

http://www.codeproject.com/Articles/3365/Embed-an-HTML-control-in-your-own-window-using-pla

like image 76
Nathan Moinvaziri Avatar answered Sep 18 '22 01:09

Nathan Moinvaziri