1

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!

Alex
  • 34,581
  • 26
  • 91
  • 135
  • if you use *c* - you need include `Uuid.Lib` to linker input - here defined `CLSID_InternetExplorer` and `IID_IWebBrowser2`. also you need use `CoCreateInstance(&CLSID_InternetExplorer, NULL, CLSCTX_ALL, &IID_IWebBrowser2, (void**)&pBrowser2);` – RbMm Feb 26 '18 at 01:34
  • however you include `-luuid` - are in your version exist `CLSID_InternetExplorer` and `IID_IWebBrowser2` ? this is from ms sdk ? – RbMm Feb 26 '18 at 01:37
  • @RbMm I suspect MinGW doesn't have these consts. If you have Visual Studio, maybe you could std::cout them ? – Alex Feb 26 '18 at 01:46
  • simply look in `uuid.lib` - are `CLSID_InternetExplorer` and `IID_IWebBrowser2` exist. in ms sdk - it exist. – RbMm Feb 26 '18 at 01:57
  • What GUI toolkit are you using – M.M Feb 26 '18 at 01:57
  • No GUI. gcc.exe. – Alex Feb 26 '18 at 02:00
  • So I found this `class DECLSPEC_UUID("0002DF01-0000-0000-C000-000000000046") InternetExplorer;` – Alex Feb 26 '18 at 02:01
  • I tried to get the CLSID via `LPCLSID guid; CLSIDFromString("{0002DF01-0000-0000-C000-000000000046}", guid); `, but it crashes... – Alex Feb 26 '18 at 02:01
  • Passing uninitialized pointers to functions is a sure recipe for disaster. You need to pass a pointer to an actual GUID instance. – IInspectable Feb 26 '18 at 02:03
  • Of course. Fixed that, but now I get `'IWebBrowser2 {aka struct IW ebBrowser2}' has no member named 'Navigate' NavigateResult = browser->Navigate(URL, &empty, &empt y, &empty, &empty); ` – Alex Feb 26 '18 at 02:10
  • @Alex [yes, it most certainly does](https://msdn.microsoft.com/en-us/library/Aa752133). – Remy Lebeau Feb 26 '18 at 02:19
  • Of course it does :) It's defined in "ExDisp.h". And yet I get this error. – Alex Feb 26 '18 at 02:24
  • I misunderstood your question. I have a normal WinAPI window. @M.M – Alex Feb 26 '18 at 02:27
  • Looks like it's simply not possible with MinGW. I hope I can link a VS library with my MinGW build. – Alex Feb 26 '18 at 02:27
  • Yep, just installed Visual Studio, and it works there. Thanks for your help. – Alex Feb 26 '18 at 02:34
  • consider using mingw-w64 which is much more up to date with Windows API than mingw – M.M Feb 26 '18 at 02:58
  • @M.M mingw-w64 is amazing! It has a full version of ExDisp.h, and it works! Can you post it as an answer so I can accept it? – Alex Feb 26 '18 at 18:43

3 Answers3

1

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.

M.M
  • 138,810
  • 21
  • 208
  • 365
0

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

Alex
  • 34,581
  • 26
  • 91
  • 135
  • @selbie the Windows SDK relies on non-standard MSVC compiler extensions ; the bulk of the work for projects like mingw involves creating headers that will work with g++ – M.M Feb 26 '18 at 03:01
0

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.

selbie
  • 100,020
  • 15
  • 103
  • 173