c++ capture screen as pixel array

#include <iostream>
#include <windows.h>

int main() {
    // Get the screen dimensions
    int screenWidth = GetSystemMetrics(SM_CXSCREEN);
    int screenHeight = GetSystemMetrics(SM_CYSCREEN);

    // Create a device context for the entire screen
    HDC hScreenDC = GetDC(NULL);

    // Create a device context for a compatible memory bitmap
    HDC hMemoryDC = CreateCompatibleDC(hScreenDC);

    // Create a bitmap compatible with the screen's device context
    HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, screenWidth, screenHeight);

    // Select the bitmap into the memory device context
    SelectObject(hMemoryDC, hBitmap);

    // Copy the screen contents into the memory device context
    BitBlt(hMemoryDC, 0, 0, screenWidth, screenHeight, hScreenDC, 0, 0, SRCCOPY);

    // Define the BITMAPINFO structure to hold information about the bitmap
    BITMAPINFOHEADER bi;
    bi.biSize = sizeof(BITMAPINFOHEADER);
    bi.biWidth = screenWidth;
    bi.biHeight = -screenHeight;  // Negative height to ensure top-down orientation
    bi.biPlanes = 1;
    bi.biBitCount = 32;           // 32 bits per pixel (RGB)
    bi.biCompression = BI_RGB;
    bi.biSizeImage = 0;
    bi.biXPelsPerMeter = 0;
    bi.biYPelsPerMeter = 0;
    bi.biClrUsed = 0;
    bi.biClrImportant = 0;

    // Get the size of the image data
    DWORD dwBmpSize = ((screenWidth  bi.biBitCount + 31) / 32)  4 * abs(bi.biHeight);

    // Allocate memory for the image data
    char* lpbitmap = new char[dwBmpSize];

    // Retrieve the bitmap data
    GetDIBits(hScreenDC, hBitmap, 0, screenHeight, lpbitmap, (BITMAPINFO*)&bi, DIB_RGB_COLORS);

    // Now lpbitmap contains the pixel data of the screen

    // Release resources
    DeleteObject(hBitmap);
    DeleteDC(hMemoryDC);
    ReleaseDC(NULL, hScreenDC);

    // Cleanup
    delete[] lpbitmap;

    return 0;
}