title: D3D11 screen desktop copy to ID3D11Texture2D
body: <p>I am writing a DLL plugin that will read the desktop frame buffer (whole screen) and render it directly into a Texture2D pointer that is passed in. The goal is to keep everything in video memory (and avoid the cost of copying back to system memory and back to video memory).</p>
  
  <p>I am able to pass the Texture2D (showing up as a ID3D11Texture2D), but I am having issues grabbing the desktop frame buffer with D3D11. D3D9 offered GetFrontBufferData() but it seems D3D11 solution is to use GetBuffer().</p>
  
  <p>My issue is about getting the IDXGISwapChain. Because I want to read the desktop frame buffer and simply read the content via GetBuffer() and display it on the ID3D11Texture2D. I am getting a ID3D11Device I do not understand how to get its IDXGISwapChain.</p>
  
  <p>I have code as follows to get the frame buffer and put it on the Texture:</p>
  
  <pre><code>ID3D11Texture2D* src = (ID3D11Texture2D*)g_TexturePointer;
  ID3D11Texture2D* dst = NULL;
  HRESULT hr = swapchain-&gt;GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&amp;dst);
  g_devCon-&gt;CopyResource(dst, src);
  </code></pre>
  
  <p>Here I actually created my own swapchain using D3D11CreateDeviceAndSwapChain() but I wonder if it is necessary as I already have a ID3D11Device.</p>
  
  <p>The CopyResource() also seems to fail.</p>