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;
}