简体   繁体   中英

Creating an IWebBrowser2 control

I just want to successfully add it to my window, and it has been surprisingly difficult.

I've tried

#include "windef.h"
#include "winbase.h"
#include "initguid.h"
#include "ole2.h"
#include "olectl.h"
#include "shobjidl.h"
#include "shlguid.h"
#include "exdispid.h"
#include <objidl.h>
#include "OleIdl.h"
#include "Objbase.h" 

#include <exdisp.h>
#include <exdispid.h>

...

IWebBrowser2* pBrowser2;
HRESULT hr = CoCreateInstance(CLSID_InternetExplorer, NULL,
    CLSCTX_ALL, IID_IWebBrowser2, (void**)&pBrowser2);

Getting

error: 'CLSID_InternetExplorer' undeclared (first use in this function)
     HRESULT hr = CoCreateInstance(CLSID_InternetExplorer,

I've also tried

CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_LOCAL_SERVER, 
                   IID_IWebBrowser2, (void**)&pBrowser2);

This one at least compiles, but nothing is added to the window:

    hr = OleCreate(&CLSID_WebBrowser, &IID_IOleObject, 1/*OLERENDER_DRAW*/, 0,
                            &ClientSite, &Storage, (void**)&mpWebObject);

I tried all headers and libraries I could find on the net (as you can see).

Here are the libraries I link:

gcc -lmingw32 -mwindows  -luser32 -lgdiplus -lole32 -luuid -loleaut32 -lcomctl32 -lcomdlg32 -ladvapi32 -loleaut32 -lshdocvw -lmf -lmfuuid

Thanks!

You could try MinGW-w64 .

This is a fork of MinGW which , in addition to supporting both 32-bit and 64-bit builds, is under much more active development. In particular, having improved Windows API headers.

Apparently MinGW doesn't support IWebBrowser2. The code worked fine in Visual Studio.

Start by including these header files first:

#include <windows.h>
#include <objbase.h>
#include <ExDisp.h>
#include <ExDispid.h>

Then this:

IWebBrowser2* pBrowser2 = nullptr;
HRESULT hr;
hr = CoCreateInstance(__uuidof(WebBrowser), NULL, CLSCTX_INPROC, __uuidof(IWebBrowser2), (void**)pBrowser2);

The use of __uuidof macro takes resolves the linkage issues to externally defined guids.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM