Reusing a web browser control

I have a clean Win32 application (without 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 you need to call SetClientSite, passing IOleClientSite *. How to get such an interface? This example implements its own browser class, which provides an interface based on it and implementing it (here) . I tried to go this route, but in order to create an instance of the browser class, I would have to register it (no?). This seems terribly complicated - I just want to use an existing COM object, and not implement and register my own. What am I missing?

Assuming I'm implementing 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 QueryInterface interface using QueryInterface )? Will this work, or is it necessary to call CoCreateInstance ?

+4
source share
3 answers

There is an example on CodeGuru , and another on CodeProject , which contains the simplest implementation for hosting a web browser implemented in pure C. You need to implement your own IOleClientSite , but this is one of the simplest classes to implement. Yes, you must call CoCreateInstance or OleCreate to instantiate a web browser OleCreate .

http://www.codeguru.com/cpp/in/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

+2
source

Try WTL (only the header library from MS). Set his project templates. Create a new WTL project from the template and select the option to control your web browser (or something else). Now you can research the generated sources or (my personal recommendations) move your materials to this project

0
source

I'm not sure what exactly you are trying to do ...

... but I would start by trying to use a simple ShellExecute (), if at all possible:

-2
source

Source: https://habr.com/ru/post/1436901/


All Articles