title: Capture screen using DirectX
body: <p>I know how to use GDI to capture screen, however it is very slow (it barely captures 10 fps)</p>
  <p>I have read that DirectX offers the best speed. But before I start learning DirectX I wanted to test a sample to see if it is really that fast.</p>
  <p>I have found this <a href="https://stackoverflow.com/questions/5069104/fastest-method-of-screen-capturing">question</a> that offers a sample code to do that:</p>
  <pre><code>void dump_buffer()
  {
     IDirect3DSurface9* pRenderTarget=NULL;
     IDirect3DSurface9* pDestTarget=NULL;
       const char file[] = &quot;Pickture.bmp&quot;;
     // sanity checks.
     if (Device == NULL)
        return;
  
     // get the render target surface.
     HRESULT hr = Device-&gt;GetRenderTarget(0, &amp;pRenderTarget);
     // get the current adapter display mode.
     //hr = pDirect3D-&gt;GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&amp;d3ddisplaymode);
  
     // create a destination surface.
     hr = Device-&gt;CreateOffscreenPlainSurface(DisplayMde.Width,
                           DisplayMde.Height,
                           DisplayMde.Format,
                           D3DPOOL_SYSTEMMEM,
                           &amp;pDestTarget,
                           NULL);
     //copy the render target to the destination surface.
     hr = Device-&gt;GetRenderTargetData(pRenderTarget, pDestTarget);
     //save its contents to a bitmap file.
     hr = D3DXSaveSurfaceToFile(file,
                                D3DXIFF_BMP,
                                pDestTarget,
                                NULL,
                                NULL);
  
     // clean up.
     pRenderTarget-&gt;Release();
     pDestTarget-&gt;Release();
  }
  </code></pre>
  <p>I have tried to include the required files. However not all of them can be included (for example <code>#include &lt;D3dx9tex.h&gt;</code>).</p>
  <p>Can anyone provide a working example that has all of the required includes or point me to what libraries I should install.</p>
  <p>I am using Visual C++ 2010 Express on Windows 7 Ultimate (x64).</p>
  <hr />
  <p><strong>Edit:</strong></p>
  <p>Also, this code is not complete, for example what is the <code>Device</code> identifier?!</p>