Click here to Skip to main content
13,503,785 members
Rate this:
Please Sign up or sign in to vote.
I want to display my image on window without saving it.
When data is received window size changes but there is no display
on window.
My Code is:
int iBufferLength;
	int iEnd;
	int iSpaceRemaining;
	int i;

	iBufferLength = iSpaceRemaining = sizeof(chIncomingDataBuffer);
	iEnd = 0;
	iSpaceRemaining -= iEnd;

	iBytesRead = recv(Socket, chIncomingDataBuffer+iEnd, iSpaceRemaining, 0);
	if (iBytesRead == SOCKET_ERROR)
						"Socket Error",
						"Connection strt",
		chIncomingDataBuffer[iEnd] = '\0';

	if (lstrlen(chIncomingDataBuffer) != 0)
		/*FILE* pfile;
					pfile = 	fopen("test.jpeg", "wb");
				fwrite(chIncomingDataBuffer,1, iBytesRead ,pfile);

				GetWindowRect(hWnd, &rect);
				SetWindowPos(hWnd, NULL, rect.left,, cBitmap.bmWidth, cBitmap.bmHeight, 0);
				  HDC ThisDC = GetDC(hWnd);

              RemoteDC = CreateCompatibleDC(ThisDC);
			  hbitmap= CreateCompatibleBitmap(ThisDC, cBitmap.bmWidth, cBitmap.bmHeight);

			  SelectObject(RemoteDC, hbitmap);

			  ReleaseDC(hWnd, ThisDC);

			  HBITMAP hbmap;
			  int bisize = sizeof(BITMAPINFO);
			  memcpy(&bi, chIncomingDataBuffer+iEnd, bisize );
			  SetDIBits(RemoteDC, hbitmap, 0,  cBitmap.bmHeight, chIncomingDataBuffer+iEnd+bisize,  &bi, DIB_RGB_COLORS);

			  InvalidateRect(hWnd, NULL, false);

Can you find my error,,,where I'm doing wrong?
Posted 5-Feb-13 21:54pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I did not check the complete code. But a cite from the MSDN GetDIBits() function shows one problem:
The bitmap identified by the hbmp parameter must not be selected into a device context when the application calls this function.
To locate such errors, it is helpful to check the return values of all functions that may indicate error conditions by return value. To limit the check to debug builds, use the ASSERT() and VERIFY() macros; e.g. for the GetDIBits() function:
VERIFY(cBitmap.height == SetDIBits(RemoteDC, hbitmap, 0,  cBitmap.bmHeight, chIncomingDataBuffer+iEnd+bisize, &bi, DIB_RGB_COLORS));

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180417.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100