title: Exception when trying to use googletest to test ATL object
body: <p>I want to write some unit tests for my COM object using googletest. Unfortunately I get an exception when <code>CreateInstance</code> is called: <code>0xC0000005: Access violation reading location 0x00000000</code>.</p>
  
  <p>The code basically looks like this:</p>
  
  <p><strong>MyClass.h</strong></p>
  
  <pre><code>class ATL_NO_VTABLE CMyClass
      : public CComObjectRootEx&lt;CComMultiThreadModel&gt;,
      public CComCoClass&lt;CMyClass, &amp;CLSID_MyClass&gt;,
      public IConnectionPointImpl&lt;CMyClass, &amp;IID_IMyClassListener&gt;,
      public IConnectionPointContainerImpl&lt;CMyClass&gt;,
      public IDispatchImpl&lt;MyComClass, &amp;IID_MyComClass, &amp;LIBID_MyLib, 1, 0&gt;
  {
      ...
  }
  </code></pre>
  
  <p><strong>Test.cpp</strong></p>
  
  <pre><code>#include "stdafx.h"
  #include "gtest/gtest.h"
  
  #include "MyClass.h"
  
  TEST(MyClassTest, IsCreated)
  {
      HRESULT hr(E_FAIL);
      CComPtr&lt;MyComClass&gt; lMyObject;
      hr = CMyClass::CreateInstance(&amp;lMyObject);
      EXPECT_EQ(S_OK, hr);
  }
  
  int main(int argc, char **argv)
  {
      ::testing::InitGoogleTest(&amp;argc, argv);
      return RUN_ALL_TESTS();
  }
  </code></pre>
  
  <p>I am able to call <code>CreateInstance</code> without any problems in some existing (non-test) projects. I don't really understand COM/ATL so I'm having trouble figuring out why I'm getting this weird exception.</p>