1

Windows GDI ImageCapturing application consumes more GDI objects(Around 320 TaskManager) Single Monitor and Encoding using GDI+ image returns User/ Kernal Marshalling Buffer has been overflowed ​ERROR_MARSHALL_OVERFLOW Marshalling Buffer Error

CImage* getCImageFromBuffer(uint8_t *rgbaBuffer, int imgWidth, int imgHeight, int imgBpp)
{
    CImage* image = NULL;

    try
    {
        if (rgbaBuffer != NULL)
        {
            image = new CImage();
            image->Create(imgWidth, imgHeight, imgBpp);

            BITMAPINFO bitmapInfo = FormBitmapInfo(imgWidth, imgHeight, imgBpp, true);

            HRESULT hErrorCode = SetDIBitsToDevice(image->GetDC(), 0, 0, imgWidth, imgHeight, 0, 0, 0, imgHeight,
                rgbaBuffer, &bitmapInfo, DIB_RGB_COLORS);

            image->ReleaseDC();

            if (FAILED(hErrorCode) && image)
            {
                cout << "FormCImageFromRGBABuffer: SetDibitsToDevice API failed "<< hErrorCode;
                delete image;
                image = NULL;
            }
            else if (FAILED(hErrorCode))
            {
                image = NULL;
            }

        }
        else
        {
            cout<< "FormCImageFromRGBABuffer failed, rgbaBuffer is null";
        }
    }
    catch(...)
    {
        cout<< "Exception in FormCImageFromRGBABuffer";
    }

    return image;
}
Dhivakar
  • 39
  • 3
  • 4
    Read the official documentation. SetDIBitsToDevice doesn't return an HRESULT but an int "If the function succeeds, the return value is the number of scan lines set. https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setdibitstodevice – Simon Mourier Jul 15 '21 at 06:12
  • 1
    Can this [question](https://stackoverflow.com/questions/68369638/taking-a-screenshot-in-windows-will-output-a-black-screen-image) help you? – YangXiaoPo-MSFT Jul 15 '21 at 07:22

0 Answers0