Why does BitBlt() fail for me?

148 Views Asked by At

I have been trying to capture the desktop, using the Windows GDI, following code available online. It works perfectly well, but I have a game that does API hooking (I believe), that blocks BitBlit() and makes it return this totally absurd return code: 126, ERROR_MOD_NOT_FOUND.

I was able to retrieve this error code via GetLastError(), and I am surprised why BitBlt() returns this error, which is giving me a clear indication that there is something happening behind the scenes here.

I am attaching a small reference of the code, I am using (actual code does lot of error checking, but I am briefing all that for context):

HDC hScreenDC = GetDC(nullptr); // CreateDC("DISPLAY",nullptr,nullptr,nullptr);
HDC hMemoryDC = CreateCompatibleDC(hScreenDC);
assert(hMemoryDC != NULL)
int width = GetDeviceCaps(hScreenDC,HORZRES);
int height = GetDeviceCaps(hScreenDC,VERTRES);
HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC,width,height);
assert(hBitmap != NULL);
HBITMAP hOldBitmap = static_cast<HBITMAP>(SelectObject(hMemoryDC,hBitmap));
if(!BitBlt(hMemoryDC,0,0,width,height,hScreenDC,0,0,SRCCOPY))
{
   // Here is the problem!
   printf("[!] An error: %d, occurred!\n", GetLastError());
}
hBitmap = static_cast<HBITMAP>(SelectObject(hMemoryDC,hOldBitmap));
DeleteDC(hMemoryDC);
DeleteDC(hScreenDC);

This code is the same as this code, but of course I am doing all the error checking in my personal code base, and that is why I understand that the error code is 126.

0

There are 0 best solutions below