title: How to get an Instance of IWebBrowser2
body: <p>I am a bit new to C++, please be gentle.</p>
  
  <p>I am trying to automate Internet Explorer. I have a simple Win32 console application where I am trying to create an instance of IE using a local server.</p>
  
  <p>However, my call to <code>CoCreateInstance()</code> doesn't return an object to initialize my <code>IWebBrowser2</code> variable.</p>
  
  <p>I could use some help to see what I am missing.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>HRESULT InstanciateIEResult;
  HRESULT NavigateResult;
  HRESULT ShowBrowserResult;
  
  VARIANT * empty = new VARIANT();
  
  BSTR URL = L"bing.com";
  IWebBrowser2*    pBrowser2;
  
  InstanciateIEResult = CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER,
      IID_IWebBrowser2, (void**)&amp;pBrowser2);
  
  
  if(pBrowser2)
  {
      //never reach here
      NavigateResult = pBrowser2-&gt;Navigate(URL, empty, empty, empty, empty);
      ShowBrowserResult = pBrowser2-&gt;put_Visible(VARIANT_TRUE);
  } 
  </code></pre>
  
  <p>I am also not sure how to decode what the <code>HRESULT</code> returns. If you know, that would be helpful as well.</p>
  
  <p>I was looking at documentation on <a href="https://msdn.microsoft.com/en-us/library/aa752127(v=vs.85).aspx" rel="nofollow noreferrer">IWebBrowser2 interface</a> and <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615(v=vs.85).aspx" rel="nofollow noreferrer">CoCreateInstance</a>.</p>