Hello Guys,
i need help with some code of mine. I am using GDIPlus and am trying to create a Get Pixel Function. My Function works fine, but unfortunately i get some weird memory issues. My GDI-Object counter in task manager increases, but I dont know why. Especially since it is not a big increase, but a small one, like 2 GDI Objects in 5 minutes eventhough i call the function multiple times per second. I added the function down here.
Best regards, thanks for the help!

Code:
INT GetColor(INT iX, INT iY, HWND WinHandle) {

int value = 0;

Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

RECT rect;
int WindowWidth;
int WindowHeight;
if (GetWindowRect(WinHandle, &rect))
{
WindowWidth = rect.right - rect.left;
WindowHeight = rect.bottom - rect.top;
}

HDC hDDC = GetDC(WinHandle);

HDC hCDC = CreateCompatibleDC(hDDC);

HBITMAP hBMP = CreateCompatibleBitmap(hDDC, WindowWidth, WindowHeight);

SelectObject(hCDC, hBMP);

BitBlt(hCDC, 0, 0, WindowWidth, WindowHeight, hDDC, 0, 0, SRCCOPY);

Gdiplus::Bitmap *BMP = new Gdiplus::Bitmap(hBMP, NULL);

Gdiplus::Color PixelColor;
BMP->GetPixel(iX, iY, &PixelColor);

Value = PixelColor.GetValue();



ReleaseDC(WinHandle, hDDC);

DeleteDC(hDDC);

DeleteDC(hCDC);

DeleteObject(hBMP);

delete BMP;

DeleteObject(BMP);

Gdiplus::GdiplusShutdown(gdiplusToken);

return Value;

}