title: DirectX 11 IDXGISwapChain::GetBuffer failing with DXGI_ERROR_INVALID_CALL
body: <p>I am creating a device and swap chain in DirectX11, then trying to get the texture of the back-buffer. The creation step appears to work but the GetBuffer call always fails with error  DXGI_ERROR_INVALID_CALL (887a0001), regardless of what I do.
  Here is the code for creating the device:</p>
  
  <pre><code>    D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_1 };
      int numFeatureLevels = sizeof(featureLevels) / sizeof(featureLevels[0]);
      DXGI_SWAP_CHAIN_DESC swapChainDesc;
      ID3D11Device* pDevice;
      IDXGISwapChain* pSwapChain;
      D3D_FEATURE_LEVEL featureLevel;
      ID3D11DeviceContext* pContext;
  
      swapChainDesc.Windowed = TRUE;
      swapChainDesc.OutputWindow = (HWND)(void*)pWindowHandle;
      swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
      swapChainDesc.SampleDesc.Count = 1;
      swapChainDesc.SampleDesc.Quality = 0;
      swapChainDesc.BufferCount = 2;
      swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
      swapChainDesc.BufferDesc.Width = 0;
      swapChainDesc.BufferDesc.Height = 0;
      swapChainDesc.BufferDesc.RefreshRate.Numerator = 1;
      swapChainDesc.BufferDesc.RefreshRate.Denominator = 60;
      swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
      swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
      swapChainDesc.BufferUsage = DXGI_USAGE_SHADER_INPUT|DXGI_USAGE_RENDER_TARGET_OUTPUT;
      swapChainDesc.Flags = 0;
  
      err = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, featureLevels, numFeatureLevels, D3D11_SDK_VERSION,
          &amp;swapChainDesc, &amp;pSwapChain, &amp;pDevice, &amp;featureLevel, &amp;pContext);
  
      if (!SUCCEEDED(err))
      {
          printf("D3D11CreateDeviceAndSwapChain failed with error %08x\n", err);
          return false;
      }
  
      m_pDevice = pDevice;
      m_pSwapChain = pSwapChain;
      m_pDeviceContext = pContext;
      m_featureLevel = featureLevel;
  
      ID3D11Texture2D* pTex = NULL;
      err = m_pSwapChain-&gt;GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)pTex);
      if (!SUCCEEDED(err))
      {
          printf("GetBuffer failed with error %08x\n", err);
          return false;
      }
  </code></pre>
  
  <p>This is Managed C++ which is compiled into a DLL and run from a C# control's OnCreateControl method, which passes Handle into the function as pWindowHandle.</p>
  
  <p>The create device call succeeds, giving me FEATURE_LEVEL_11_0, but the second printf function is always printing error 887a0001. Using the reference device does not help. I'm linking against d3dx11.lib, d3d11.lib, dxgi.lib, dxguid.lib, d3dcompiler.lib, d3d10.lib and d3dx10.lib.
  I tried replacing the __uuidof with IID_ID3D11Texture2D and that made no difference.
  I am using Visual Studio Express 2013 for Windows Desktop, on Windows 7, and the Microsoft DirectX SDK (June 2010). All x86 and x64, Debug and Release builds suffer from the same problem. My attempts to enable verbose debug output also fail; I have tried to force it on via the DirectX Properties in Control Panel, adding my program to the list of executables, but nothing extra is printed at runtime.</p>