IWebBrowser2 function error

Hello everyone!

I just found about IWebBrowser2. Here's an example I found on msdn webpage that I can't seem to get working.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
if (SUCCEEDED(OleInitialize(NULL)))
{
   IWebBrowser2*    pBrowser2;

   CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, 
                       IID_IWebBrowser2, (void**)&pBrowser2);
   if (pBrowser2)
   {
       VARIANT vEmpty;
       VariantInit(&vEmpty);

       BSTR bstrURL = SysAllocString(L"http://microsoft.com");

       HRESULT hr = pBrowser2->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);
       if (SUCCEEDED(hr))
       {
           pBrowser2->put_Visible(VARIANT_TRUE);
       }
       else
       {
           pBrowser2->Quit();
       }

       SysFreeString(bstrURL);
       pBrowser2->Release();
   }

   OleUninitialize();
}


link: http://msdn.microsoft.com/en-us/library/aa752127(v=vs.85).aspx

They say I should include Exdisp.h, but I'm still getting errors. How can I resolve this issue?

Note, I used the code snippet above is inside the main function.
I'm using Code::Blocks with MinGW
Mingw does not have required headers. Maybe you could copy structure definitions from Microsoft headers.
I recommend you to use Visual Studio for COM programming.
Well, all header files should be included in the Windows SDK, even the COM ones. You could download and install the latest SDK and configure Code::Blocks to use these.

But you should post the errors anyway to ensure you get proper replies.
Last edited on
Add this line to your code:
EXTERN_C CLSID CLSID_InternetExplorer;

Don't forget to link with oleaut32, ole32 and uuid libraries.

I successfully compiled the code myself.
Topic archived. No new replies allowed.