title: Taking screenshot C++ directx gets black image
body: <p>I'm trying to take a screen capture with directx. I tried code from several pages that explains how but always get a black screen shot. If someone can help me I will be grateful.</p>
  
  <p>my code is:</p>
  
  <pre><code>int _tmain(int argc, _TCHAR* argv[])
  {
      IDirect3DDevice9* g_pd3dDevice;
      //SaveScreenShot("test.bmp",D3DXIFF_BMP);   
      IDirect3DSurface9* pSurface=NULL;
      //IDirect3DSurface9* pSource=NULL;
      D3DPRESENT_PARAMETERS d3dpp;
      ZeroMemory(&amp;d3dpp, sizeof(d3dpp));
      d3dpp.Windowed = FALSE;
      d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
      d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
      d3dpp.BackBufferCount = 1;
      d3dpp.BackBufferWidth = 1280;
      d3dpp.BackBufferHeight = 1024;
      d3dpp.hDeviceWindow = GetDesktopWindow();
      d3dpp.FullScreen_RefreshRateInHz=0;
      d3dpp.MultiSampleQuality=0;
      IDirect3D9* direct=Direct3DCreate9(D3D9b_SDK_VERSION);
      direct-&gt;CreateDevice(D3DADAPTER_DEFAULT,
                           D3DDEVTYPE_HAL,
                           GetDesktopWindow(),
                           D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                           &amp;d3dpp,&amp;g_pd3dDevice);
  
  
      //g_pd3dDevice-&gt;GetRenderTarget(0,&amp;pSource);
      g_pd3dDevice-&gt;CreateOffscreenPlainSurface(1280, 1024,
          D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &amp;pSurface, NULL);
      g_pd3dDevice-&gt;GetFrontBufferData(0, pSurface);
      /*g_pd3dDevice-&gt;GetRenderTargetData(pSource,pSurface);
      g_pd3dDevice-&gt;GetRenderTargetData(pSource,pSurface);*/
      D3DXSaveSurfaceToFile("Desktop.jpg",D3DXIFF_JPG,pSurface,NULL,NULL);
      pSurface-&gt;Release();
      //pSource-&gt;Release();
      return 0;
  }
  </code></pre>