title: CXX0030: Error: expression cannot be evaluated
body: <p><strong>The short question:</strong> </p>
  
  <p><em>Why am I see this in the Locals window for my IWICImagingFactory object while in my destructor?</em></p>
  
  <p><strong>The long explanation:</strong></p>
  
  <p>I am creating a IWICImagingFactory object in my CreateDeviceIndependentResources() function:</p>
  
  <pre><code>if (SUCCEEDED(hr))
  {
      hr = CoCreateInstance(
          CLSID_WICImagingFactory,
          NULL,
          CLSCTX_INPROC_SERVER,
          IID_PPV_ARGS(&amp;mpWICFactory)
          );
  }
  </code></pre>
  
  <p>I have checked hr after this and it is always S_OK. </p>
  
  <p>Then in my CreateDeviceResources() function I pass a pointer to the IWICImagingFactory object in a call to LoadBitmapFromFile():</p>
  
  <pre><code>    if(SUCCEEDED(hr))
      {
          hr = LoadBitmapFromFile(
              mpRenderTarget,
              mpWICFactory,
              L".\\background.png",
              0,
              0,
              &amp;mpBackgroundBitmap);
      }
  </code></pre>
  
  <p>The function LoadBitmapFromFile is exactly as it appears in the MSDN sample. You can see most of the code here: <a href="http://msdn.microsoft.com/en-us/library/dd756686%28v=VS.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd756686%28v=VS.85%29.aspx</a></p>
  
  <p>The return code from LoadBitmapFromFile() is S_OK. I now have a ID2D1Bitmap object which works fine.</p>
  
  <p>I don't use the WIC factory for anything else. The problem occurs in my destructor when I try to SafeRelease() the WIC factory:</p>
  
  <pre><code>SafeRelease(&amp;mpWICFactory);
  </code></pre>
  
  <p>SafeRelease() is defined as:</p>
  
  <pre><code>template&lt;class Interface&gt;
  inline void SafeRelease(Interface** ppInterfaceToRelease)
  {
  if(*ppInterfaceToRelease != NULL)
  {
      (*ppInterfaceToRelease)-&gt;Release();
      (*ppInterfaceToRelease) = NULL;
  }
  
  }
  </code></pre>
  
  <p>While in the destructor, if I expand the mpWICFactory object in the Locals window, I see the "CXX0030: Error: expression cannot be evaluated" errors. The screenshot below shows the Locals window right before calling SafeRelease() on the WICFactory object.</p>
  
  <p><a href="http://img21.imageshack.us/img21/9820/localsy.jpg" rel="nofollow">http://img21.imageshack.us/img21/9820/localsy.jpg</a></p>
  
  <p>I then get an error:
  Unhandled exception at 0x00d22395 in Program.exe: 0xC0000005: Access violation reading location 0x6df128f0.</p>
  
  <p>What is the cause of this problem?</p>
  
  <p>EDIT: Here is a full simple program demonstrating the problem:</p>
  
  <p>Test.h</p>
  
  <pre><code>#ifndef TEST_H
  #define TEST_H
  
  #include &lt;Windows.h&gt;
  #include &lt;wincodec.h&gt;
  #include &lt;d2d1.h&gt;
  
  class Test
  {
  public:
  
  IWICImagingFactory *mpWICFactory;
  
  Test();
  ~Test();
  
  HRESULT Init();
  };
  
  template&lt;class Interface&gt;
  inline void SafeRelease(Interface** ppInterfaceToRelease)
  {
  if(*ppInterfaceToRelease != NULL)
  {
      (*ppInterfaceToRelease)-&gt;Release();
      (*ppInterfaceToRelease) = NULL;
  }
  
  }
  
  #endif
  </code></pre>
  
  <p>Test.cpp</p>
  
  <pre><code>#include "Test.h"
  
  Test::Test() : mpWICFactory(NULL)
  {
  }
  
  Test::~Test()
  {
  SafeRelease(&amp;mpWICFactory);
  }
  
  HRESULT Test::Init()
  {
     HRESULT hr = CoCreateInstance(
          CLSID_WICImagingFactory,
          NULL,
          CLSCTX_INPROC_SERVER,
          IID_PPV_ARGS(&amp;mpWICFactory)
          );
  
     return hr;
  }
  </code></pre>
  
  <p>Main.cpp</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include "Test.h"
  
  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
                 PSTR cmdLine, int showCmd)
  {
  if(SUCCEEDED(CoInitialize(NULL)))
  {
      Test app;
  
      app.Init();
  
      CoUninitialize();
  }
  
  return 0;
  }
  </code></pre>