Problem with creating Bitmap from Screen in WinCE7 Application

Hello dear Toradex community,

I have a Silverlight application for WinCE7 on a Toradex T20 module, which is written in C++

Now I want to implement a screenshot feature that saves the whole screen content into a bitmap file.

I found many examples for this. The following code snippet should load the whole screen into a bitmap:

	const POINT tlp = DetermineTopLeftCornerPosition();
	const POINT brp = DetermineBottomRightCornerPosition();
	DWORD err;
	HWND windowHandle = NULL;

	HDC hs = GetDC(NULL);
	HDC hdc = CreateCompatibleDC(hs);
	HBITMAP hb = CreateCompatibleBitmap(hs, abs(brp.x - tlp.x), abs(brp.y - tlp.y));
	HGDIOBJ ho = SelectObject(hdc, hb);
	DWORD err = GetLastError();
	BitBlt(hdc, 0, 0, abs(brp.x - tlp.x), abs(brp.y - tlp.y), hs, tlp.x, tlp.y, SRCCOPY);

The problem seems to lie in the function SelectObject(...). The following call of GetLastError(), gives me the error code 6, which indicates an invalid handle.

On my PC (Win10) this code does work, but not on CE.

Does anyone have an idea what I am doing wrong here?

Many thanks in advance for helpful answers.

Dear @Dave,

Thank you for contacting the Toradex community!.

I am not sure exactly which is missing here. May I request you refer a sample code to find the issue and fix it. Please refer CERDISP code from the Microsft platform builder installation on this path : (C:\WINCE700\public\common\oak\drivers\CErDisp\Cerdisp).

This CERDISP application taking GDI display buffer data and transfer it to PC through socket APIs.

We have released the binary application here : https://developer.toradex.com/knowledge-base/remote-display

Please let us know if you face any issues with this.