title: Having issues with byte array/capturing a screenshot
body: <p>Hi guys I have the following code:</p>
  
  <pre><code>#define ScreenXResolution GetDeviceCaps(GetDC(0), HORZRES)
  #define ScreenYResolution GetDeviceCaps(GetDC(0), VERTRES)
  
  BYTE *screenData = malloc(sizeof(BYTE) * (3 * ScreenXResolution * ScreenYResolution));
  captureScreenshot(&amp;screenData);
  
  void captureScreenshot(BYTE *screenData)
  {
      HDC hdc = GetDC(NULL), hdcMem = CreateCompatibleDC(hdc);
      HBITMAP hBitmap = CreateCompatibleBitmap(hdc, ScreenXResolution, ScreenYResolution);
      BITMAPINFOHEADER bmi = {0};
      bmi.biSize = sizeof(BITMAPINFOHEADER);
      bmi.biPlanes = 1;
      bmi.biBitCount = 24;
      bmi.biWidth = ScreenXResolution;
      bmi.biHeight = -ScreenYResolution;
      bmi.biCompression = BI_RGB;
      SelectObject(hdcMem, hBitmap);
      BitBlt(hdcMem, 0, 0, ScreenXResolution, ScreenYResolution, hdc, 0, 0, SRCCOPY);
      GetDIBits(hdc, hBitmap, 0, ScreenYResolution, screenData, (BITMAPINFO*)&amp;bmi, DIB_RGB_COLORS);
      DeleteObject(hBitmap);
      DeleteDC(hdcMem);
      ReleaseDC(NULL, hdc);
  }
  </code></pre>
  
  <p>What I'm trying to achieve is taking a screenshot of their screen and putting it in screenData.</p>
  
  <p>The reason why I  need that is so I can check if it's a certain RGB color at whichever position but I'm having issues doing so.</p>
  
  <p>If anyone could help me out that would be greatly appreciated.</p>
  
  <p>thanks!</p>
  
  <p>edit: Added the memory allocation, The way I try to get the RGB is by a function returning a colorref like this:</p>
  
  <pre><code>COLORREF getRGBFromScreenshot(BYTE *screenshot, int x, int y)
  {
      return RGB(screenshot[3 * ((y * ScreenXResolution) + x) + 2], screenshot[3 * ((y * ScreenXResolution) + x) + 1], screenshot[3 * ((y * ScreenXResolution) + x)]);
  }
  </code></pre>