[win32] Send bitmap over socket - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 45

Thread: [win32] Send bitmap over socket

  1. #16
    Join Date
    Apr 1999
    Posts
    27,424

    Re: [win32] Send bitmap over socket

    Quote Originally Posted by DaigonoYouso View Post
    the way you reply,
    And what is "the way"? You asked a question, I answered it. What are you expecting as a reply?

    Where in any of my responses do you see violence even suggested against you? I even took the time to show you where your memory leak was and how to fix it. Do you still want to "punch in the face with a chair"?
    I didnt threat you nor harassed you in any way
    Punching in face with a chair -- ok, that is not harassment or threatening.

    And you expect others to help you with the likelihood of being given a response like that?

    Regards,

    Paul McKenzie

  2. #17
    Join Date
    Oct 2013
    Posts
    39

    Re: [win32] Send bitmap over socket

    Quote Originally Posted by Paul McKenzie View Post
    And what is "the way"? You asked a question, I answered it. What are you expecting as a reply?

    Where in any of my responses do you see violence even suggested against you? I even took the time to show you where your memory leak was and how to fix it. Do you still want to "punch in the face with a chair"?
    Punching in face with a chair -- ok, that is not harassment or threatening.

    And you expect others to help you with the likelihood of being given a response like that?

    Regards,

    Paul McKenzie
    I fixed the leak before I saw it here, but that doesnt matter, thank you, this was like the first time ever you were useful to me

    also, did I punch you, or did I said that I feel like that? punching and feeling like that are 2 totally different things, just as trying to help and helping, u know?

    anyone who's willing to help? sending code:

    Code:
    				RECT rc;
    				GetClientRect(GetDesktopWindow(), &rc);
    
    				HDC hDC = CreateCompatibleDC(NULL);
    				HBITMAP hBmp = CreateCompatibleBitmap(GetDC(NULL), rc.right, rc.bottom);
    
    				SelectObject(hDC, hBmp);
    				BitBlt(hDC, 0, 0, rc.right, rc.bottom, GetDC(NULL), 0, 0, SRCCOPY);
    
    				BYTE* buff;
    				LPBITMAPINFO pbi = CreateBitmapInfoStruct(hBmp);
    
    				buff = new BYTE[pbi->bmiHeader.biSizeImage];
    
    				GetDIBits(hDC, hBmp, 0, (WORD)pbi->bmiHeader.biHeight, buff, pbi, DIB_RGB_COLORS);
    
    				send(ps.GetSocket(-1), (char*)pbi, sizeof(LPBITMAPINFO), NULL);
    
    				send(ps.GetSocket(-1), (char*)buff, (int)pbi->bmiHeader.biSizeImage, NULL);
    				
    				delete[] buff;
    				ReleaseDC(hWnd, hDC);
    				DeleteDC(hDC);
    				DeleteObject(hBmp);
    when I recreate the bitmap in the client, it works (using "pbi" and buff I created before), however, I don't know how to recreate LPBITMAPINFO on the server, after I send it from the client, code to recreate bitmap with pbi and buff:
    Code:
    				HDC hDC2 = CreateCompatibleDC(NULL);
    				HBITMAP hBitmap = CreateCompatibleBitmap(GetDC(NULL), rcView.right, rcView.bottom);
    
    				SelectObject(hDC2, hBitmap);
    
    				SetDIBits(hDC2, hBitmap, 0, 1600, buff, pbi, DIB_RGB_COLORS);
    
    				HDC hWindow = GetDC(hViewWnd);
    				SetStretchBltMode(hWindow, HALFTONE);
    				StretchBlt(hWindow, 0, 0, rcView.right, rcView.bottom, hDC2, 0, 0, 1600, 900, SRCCOPY);
    
    				DeleteDC(hWindow);
    				ReleaseDC(hWnd, hDC2);
    				DeleteDC(hDC2);
    				DeleteObject(hBitmap);
    Last edited by DaigonoYouso; January 5th, 2014 at 05:31 PM.

  3. #18
    Join Date
    Apr 1999
    Posts
    27,424

    Re: [win32] Send bitmap over socket

    I have sent you private email.

    Having said that, your code still has an error:
    Code:
    send(ps.GetSocket(-1), (char*)pbi, sizeof(LPBITMAPINFO), NULL);
    LPBITMAPINFO is a pointer, and the sizeof a pointer will either be 4 or 8, depending on whether the application is 32 o 64 bit. What you want is this:
    Code:
    send(ps.GetSocket(-1), (char*)pbi, sizeof(BITMAPINFO), NULL)
    This is the correction. With this, you are now properly sending the number of bytes a BITMAPINFO consists of.

    Regards,

    Paul McKenzie

  4. #19
    Join Date
    Oct 2013
    Posts
    39

    Re: [win32] Send bitmap over socket

    I still somehow can't manage to retrieve the bitmap properties, sending code:

    Code:
    					RECT rc;
    					GetClientRect(GetDesktopWindow(), &rc);
    
    					HDC hDC = CreateCompatibleDC(NULL);
    					HBITMAP hBmp = CreateCompatibleBitmap(GetDC(NULL), rc.right, rc.bottom);
    
    					SelectObject(hDC, hBmp);
    					BitBlt(hDC, 0, 0, rc.right, rc.bottom, GetDC(NULL), 0, 0, SRCCOPY);
    
    					BYTE* buff;
    					LPBITMAPINFO pbi = CreateBitmapInfoStruct(hBmp);
    
    					buff = new BYTE[pbi->bmiHeader.biSizeImage];
    
    					GetDIBits(hDC, hBmp, 0, (WORD)pbi->bmiHeader.biHeight, buff, pbi, DIB_RGB_COLORS);
    
    					send(ps.GetSocket(-1), (char*)pbi, sizeof(BITMAPINFO), NULL);
    
    					send(ps.GetSocket(-1), (char*)buff, (int)pbi->bmiHeader.biSizeImage, NULL);
    
    					ReleaseDC(hWnd, hDC);
    					DeleteDC(hDC);
    					DeleteObject(hBmp);
    now I have 2 global variables on my server

    Code:
    BITMAPINFO pbi;
    BYTE* imageBuff;
    bool bInfo = true;
    now, on FD_READ I have this:

    Code:
    				if(bInfo)
    				{
    					int size = sizeof(BITMAPINFO);
    					BYTE *buff = new BYTE[size];
    					int a = recv((SOCKET)wParam, (char*)buff, size, 0);
    					if(a > 0)
    						memcpy(&pbi, buff, size);
    					
    					bInfo = false;
    					delete[] buff;
    				}
    				else
    				{
    					int size = pbi.bmiHeader.biSizeImage;
    					imageBuff = new BYTE[size];
    					BYTE *buff = new BYTE[size];
    					int a = recv((SOCKET)wParam, (char*)buff, size, 0);
    					if(a > 0)
    						memcpy(imageBuff, buff, size);
    
    					bInfo = true;
    					delete[] buff;
    				}
    which is supposed to:

    if bInfo is true, I'm getting BITMAPINFO struct, so:

    1. set DATA buffer size to size of struct
    2. receive data
    3. copy bitmapinfo properties from buff and set them to pbi
    4. set bInfo to false, since Im not gonna get bInfo next, but that second thing
    5. delete buff

    if bInfo is false, I'm getting the second thing, so:

    1. set DATA imageBuff size to size of image, since we got that one before
    2. receive data and store them in buffer
    3. copy buffer to imagebuff, so we can recreate the bitmap
    4. set bInfo to true, since im gonna get bitmapinfo next
    5. delete buff

    I'm getting std::bad_alloc here (after I get the second thing, bitmapinfo is fine if I remember right)

    edit: I'm sending both, bitmapinfo and the second thing, however with debug points I discovered that it goes to memcpy 3 times (it is supposed to do only once, since I'm sending only 1 bitmap so far), and I get bad_alloc on the third time (it's getting bitmapinfo second time)
    Last edited by DaigonoYouso; January 5th, 2014 at 06:50 PM.

  5. #20
    Join Date
    Apr 1999
    Posts
    27,424

    Re: [win32] Send bitmap over socket

    Quote Originally Posted by DaigonoYouso View Post
    I still somehow can't manage to retrieve the bitmap properties, sending code:
    Maybe it would be better to send

    1) BITMAPINFO struct data
    2) The number of bytes that the image data in step 3) consists of
    3) The actual image data.

    Then on the receiving side, receive the information exactly in this way. Since BITMAPINFO is the same size, you don't need to specify the size on the send, but the bitmap data can vary, so it is easier to first send how much data is being sent, and then the actual data (to me, this would be easier, others may differ).

    Also, I suggest you use std::vector<BYTE> instead of new[]/delete[]. Doing so will remove most, if not all of the std::bad_alloc() errors you're receiving. If you forget to deallocate somewhere using new[], you get a memory leak. Using vector will alleviate that problem so that you can get along with your work (later on, you can see if you're not releasing the vector at a "good" time, but regardless, the memory will be released automatically thus not stopping you dead in your tracks).

    For example:
    Code:
    BITMAPINFO bInfo;
    int size = sizeof(BITMAPINFO);
    std::vector<BYTE> buf(size);
    int a = recv((SOCKET)wParam, (char*)&buff[0], size, 0);
    if(a > 0)
        memcpy(&bInfo, &buff[0], size);
    Note that we are creating a vector, setting its size in terms of capacity. Then reading the data into the vector and lastly, copying the data from the vector to the BITMAPINFO variable. Note also that the variable type is BITMAPINFO and not LPBITMAPINFO.

    But note that we don't call delete[]. The vector will automatically delete the memory it uses when the vector goes out of scope.

    Regards,

    Paul McKenzie

  6. #21
    Join Date
    Oct 2013
    Posts
    39

    Re: [win32] Send bitmap over socket

    well, since I'm SENDING packet with size pbi->bmiHeader.biSizeImage, then the size can't be wrong on accept, IF I receive a valid bitmapinfo data, anyway, I have this code

    Code:
    				if(bInfo)
    				{
    					int size = sizeof(BITMAPINFO);
    					vector<BYTE> buff(size);
    					int a = recv((SOCKET)wParam, (char*)&buff[0], size, 0);
    					if(a > 0)
    						memcpy(&bi, &buff[0], size);
    					
    					bInfo = false;
    				}
    				else
    				{
    					int size = bi.bmiHeader.biSizeImage;
    					imageBuff.resize(size);
    					vector<BYTE> buff(size);
    					int a = recv((SOCKET)wParam, (char*)&buff[0], size, 0);
    					if(a > 0)
    						memcpy(&imageBuff[0], &buff[0], size);
    
    					bInfo = true;
    				}
    BUT I'm STILL going thru all of this 2 times, and on the second time, I'm getting bad_alloc on imageBuff.resize(size)... also since I never worked with vectors, am I using them right in memcpy and in this function?

    Code:
    SetDIBits(hDC2, hBitmap, 0, 1600, &imageBuff[0], &bi, DIB_RGB_COLORS);
    or am I supposed to use &imageBuff, instead of &imageBuff[0] ?

  7. #22
    Join Date
    Apr 1999
    Posts
    27,424

    Re: [win32] Send bitmap over socket

    Code:
    		int size = bi.bmiHeader.biSizeImage;
    		imageBuff.resize(size);
    Make sure that "size" is valid. It more than likely is a weird number, as vectors don't "crash" on resize() unless size is invalid (or you've really messed up the heap manager in some way, which is highly unlikely to affect vector in this way).
    Code:
    also since I never worked with vectors, am I using them right in memcpy and in this function?
    The usage of vector is correct (&imageBuff[0]). The way it works is that a vector is a wrapper around a (dynamic), contiguous array, not really different than the naked "new[]" call. The difference is that vector is safer and will "delete []" memory when vector goes out of scope.

    To get to the vector's internal array is to point to the first element, and that is what "&imageBuffer[0]" does. Since the vector stores BYTE data, a pointer to the first element is a BYTE*, exactly the same if you used new[]. However you must make sure that

    1) The imageBuff vector is not empty. If it is empty, then imageBuff[0] doesn't exist, causing an error.
    2) The other parameters to SetDIBits are actually correct in terms of the bitmap you're handling.

    Regards,

    Paul McKenzie

  8. #23
    Join Date
    Oct 2013
    Posts
    39

    Re: [win32] Send bitmap over socket

    I'm totally lost now, I have this code for sending:

    Code:
    					RECT rc;
    					GetClientRect(GetDesktopWindow(), &rc);
    
    					HDC hDC = CreateCompatibleDC(NULL);
    					HBITMAP hBmp = CreateCompatibleBitmap(GetDC(NULL), rc.right, rc.bottom);
    
    					SelectObject(hDC, hBmp);
    					BitBlt(hDC, 0, 0, rc.right, rc.bottom, GetDC(NULL), 0, 0, SRCCOPY);
    
    					BYTE* buff;
    					LPBITMAPINFO pbi = CreateBitmapInfoStruct(hBmp);
    
    					buff = new BYTE[pbi->bmiHeader.biSizeImage];
    
    					GetDIBits(hDC, hBmp, 0, (WORD)pbi->bmiHeader.biHeight, buff, pbi, DIB_RGB_COLORS);
    
    					send(ps.GetSocket(-1), (char*)pbi, sizeof(BITMAPINFO), NULL);
    
    					char cSize[36];
    					stringstream ss;
    					ss << pbi->bmiHeader.biSizeImage;
    					ss >> cSize;
    					MessageBox(hWnd, cSize, NULL, NULL);
    					send(ps.GetSocket(-1), cSize, strlen(cSize), NULL);
    
    					send(ps.GetSocket(-1), (char*)buff, (int)pbi->bmiHeader.biSizeImage, NULL);
    
    					ReleaseDC(hWnd, hDC);
    					DeleteDC(hDC);
    					DeleteObject(hBmp);
    this code for receiving :

    Code:
    				if(iStep == 0)
    				{
    					int size = sizeof(BITMAPINFO);
    					vector<BYTE> buff(size);
    					int a = recv((SOCKET)wParam, (char*)&buff[0], size, 0);
    					if(a > 0)
    						memcpy(&bi, &buff[0], size);
    				
    					iStep++;
    					Log(hWnd, "First");
    				}
    				else if(iStep == 1)
    				{
    					char buff[36];
    					int a = recv((SOCKET)wParam, buff, 36, 0);
    					stringstream ss;
    					ss << buff;
    					ss >> iBuffSize;
    					Log(hWnd, buff);
    					iStep++;
    					Log(hWnd, "Sec");
    				}
    				else if(iStep == 2)
    				{
    					imageBuff.resize(iBuffSize);
    					vector<BYTE> buff(iBuffSize);
    					int a = recv((SOCKET)wParam, (char*)&buff[0], iBuffSize, 0);
    					if(a > 0)
    						memcpy(&imageBuff[0], &buff[0], iBuffSize);
    
    					SendMessage(hWnd, WM_USER + 3, NULL, NULL);
    					iStep = 0;
    					Log(hWnd, "Thrd");
    				}
    BUT I send only ONE bitmap (when I press button), AND it loops SEVERAL times, here's the output from Log function

    http://pastebin.com/h2r3zKR4

    as you can see, it goes FINE first time (even size is fine), BUT it then processes message several times, WHY?

    this does not happen when I send simple char array, containing "hello server" or something

    edit: I also tried to add
    Code:
    					stringstream ss;
    					ss << bi.bmiHeader.biSizeImage;
    					char tmp[32];
    					ss >> tmp;
    					Log(hWnd, tmp);
    to the first step (when receiving bitmap), and IT IS receiving the right size (5760000), so bitmapinfo is transfered and retrieved fine, I guess, however the bitmap data (or however itis called) is not, since Its drawing a blackscreen (this can also becaused because of the other messages that are getting processed)

    edit2: nope, I made it to not set iStep to 0 after receiving data, so it will process it only once, however it draws just a black screen, so there are 2 errors now:

    1. data are not sent/retrieved as they should be
    2. it processes one bitmap 157 times

    edit3: so I spent whole night trying to do ANYTHING, well, I made new codes for sending and receiving, HOWEVER when I leave first if scope in receiving code, I get "breakpoint occured" visual studio error, or something like that, and it just crashes

    Code:
    					RECT rc;
    					GetClientRect(GetDesktopWindow(), &rc);
    
    					HDC hDC = CreateCompatibleDC(NULL);
    					HBITMAP hBmp = CreateCompatibleBitmap(GetDC(NULL), rc.right, rc.bottom);
    
    					SelectObject(hDC, hBmp);
    					BitBlt(hDC, 0, 0, rc.right, rc.bottom, GetDC(NULL), 0, 0, SRCCOPY);
    
    					BYTE* buff;
    					LPBITMAPINFO pbi = CreateBitmapInfoStruct(hBmp);
    
    					buff = new BYTE[pbi->bmiHeader.biSizeImage];
    
    					GetDIBits(hDC, hBmp, 0, (WORD)pbi->bmiHeader.biHeight, buff, pbi, DIB_RGB_COLORS);
    					
    					char command[] = "client_bitmapinfo ";
    
    					int size = sizeof(BITMAPINFO) + pbi->bmiHeader.biSizeImage + strlen(command);
    
    					char msg[64];
    					wsprintf(msg, "client_bitmap %d", size);
    					send(ps.GetSocket(-1), msg, strlen(msg), NULL);
    
    					vector<BYTE> data(size);
    
    					memcpy(&data[0], command, strlen(command));
    					int i = strlen(command);
    					memcpy(&data[0+i], pbi, sizeof(BITMAPINFO));
    					i += sizeof(BITMAPINFO);
    					memcpy(&data[0+i], buff, pbi->bmiHeader.biSizeImage);
    
    					send(ps.GetSocket(-1), (char*)&data[0], size, 0);
    and this code for receiving:

    Code:
    				char buff[64];
    				int res = recv((SOCKET)wParam, buff, 64, 0);
    				if(res > 0)
    				{
    					buff[res] = '\0';
    					int len = strlen("client_bitmap ");
    					int len2 = strlen("client_bitmapinfo ");
    					if(strncmp(buff, "client_bitmap ", len) == 0)
    					{
    						char tmp[32];
    						strncpy_s(tmp, buff+len, res-len);
    						stringstream ss;
    						ss << tmp;
    						ss >> iBuffSize;
    					} //crash
    					else if(strncmp(buff, "client_bitmapinfo ", len2) == 0)
    					{
    						int curpos = len2;
    						vector<BYTE> data(iBuffSize);
    						int res = recv((SOCKET)wParam, (char*)&data[0], iBuffSize, 0); // this probably wont work, but I can't test it, since I can't get out of first scope
    						if(res > 0)
    						{
    							memcpy(&bi, &data[0+curpos], sizeof(BITMAPINFO));
    							curpos += sizeof(BITMAPINFO);
    							imageBuff.resize(iBuffSize-curpos);
    							memcpy(&imageBuff[0], &data[0+curpos], iBuffSize-curpos);
    						}
    					}
    				}
    Last edited by DaigonoYouso; January 6th, 2014 at 12:46 AM.

  9. #24
    Join Date
    Apr 1999
    Posts
    27,424

    Re: [win32] Send bitmap over socket

    Quote Originally Posted by DaigonoYouso View Post
    I'm totally lost now, I have this code for sending:
    Code:
    	BYTE* buff;
    	LPBITMAPINFO pbi = CreateBitmapInfoStruct(hBmp);
    	buff = new BYTE[pbi->bmiHeader.biSizeImage];
    Where is that memory released? You should just use vector here, just as in the other place.
    Code:
    char buff[64];
    int res = recv((SOCKET)wParam, buff, 64, 0);
    if(res > 0)
    {
        buff[res] = '\0';
    What if "res" is 64? You have a buffer overwrite since the largest index that buf can safely address is buf[63]. This is a memory overwrite by 1 byte.
    Code:
    ps.GetSocket(-1)
    Why not store this value in a variable, so that you aren't repeatedly calling this function?

    Also, I see a potential for many of these "off-by-1" errors. These errors can cause C++ programs to crash or overwrite other variables. It would also help if you posted the entire program, as memory overwrites anywhere can cause issues in other places later on in the running of the program.

    Regards,

    Paul McKenzie

  10. #25
    Join Date
    Oct 2013
    Posts
    39

    Re: [win32] Send bitmap over socket

    Quote Originally Posted by Paul McKenzie View Post
    Code:
    	BYTE* buff;
    	LPBITMAPINFO pbi = CreateBitmapInfoStruct(hBmp);
    	buff = new BYTE[pbi->bmiHeader.biSizeImage];
    Where is that memory released? You should just use vector here, just as in the other place.
    Code:
    char buff[64];
    int res = recv((SOCKET)wParam, buff, 64, 0);
    if(res > 0)
    {
        buff[res] = '\0';
    What if "res" is 64? You have a buffer overwrite since the largest index that buf can safely address is buf[63]. This is a memory overwrite by 1 byte.
    Code:
    ps.GetSocket(-1)
    Why not store this value in a variable, so that you aren't repeatedly calling this function?

    Also, I see a potential for many of these "off-by-1" errors. These errors can cause C++ programs to crash or overwrite other variables. It would also help if you posted the entire program, as memory overwrites anywhere can cause issues in other places later on in the running of the program.

    Regards,

    Paul McKenzie
    I'm storing socket as "mySocket" now, anyway when I send a bitmap, it will again process the message several times and spam my log, and the bitmap is black

    Code:
    				int size;
    				if(!bGotInfo)
    					size = 64;
    				else
    					size = iBuffSize;
    				
    				vector<BYTE> buff(size);
    				int res = recv((SOCKET)wParam, (char*)&buff[0], size, 0);
    				if(res > 0)
    				{
    					if(res != size)
    						buff[res] = '\0';
    					
    					Log(hWnd, (char*)&buff[0]);
    
    					int len = strlen("client_bitmap ");
    					int len2 = strlen("client_bitmapinfo ");
    					if(strncmp((char*)&buff[0], "client_bitmap ", len) == 0)
    					{
    						char tmp[32];
    						strncpy_s(tmp, (char*)&buff[0+len], res-len);
    						stringstream ss;
    						ss << tmp;
    						ss >> iBuffSize;
    						bGotInfo = true;
    					}
    					else if(strncmp((char*)&buff[0], "client_bitmapinfo ", len2) == 0)
    					{
    						int curpos = len2;
    						memcpy(&bi, &buff[0+curpos], sizeof(BITMAPINFO));
    						curpos += sizeof(BITMAPINFO);
    						imageBuff.resize(iBuffSize-curpos);
    						memcpy(&imageBuff[0], &buff[0+curpos], iBuffSize-curpos);
    						SendMessage(hWnd, WM_USER+3, NULL, NULL);
    						bGotInfo = false;
    					}
    				}
    Code:
    					RECT rc;
    					GetClientRect(GetDesktopWindow(), &rc);
    
    					HDC hDC = CreateCompatibleDC(NULL);
    					HBITMAP hBmp = CreateCompatibleBitmap(GetDC(NULL), rc.right, rc.bottom);
    
    					SelectObject(hDC, hBmp);
    					BitBlt(hDC, 0, 0, rc.right, rc.bottom, GetDC(NULL), 0, 0, SRCCOPY);
    
    					BYTE* buff;
    					LPBITMAPINFO pbi = CreateBitmapInfoStruct(hBmp);
    
    					buff = new BYTE[pbi->bmiHeader.biSizeImage];
    
    					GetDIBits(hDC, hBmp, 0, (WORD)pbi->bmiHeader.biHeight, buff, pbi, DIB_RGB_COLORS);
    					
    					char command[] = "client_bitmapinfo ";
    
    					int size = sizeof(BITMAPINFO) + pbi->bmiHeader.biSizeImage + strlen(command);
    
    					char msg[64];
    					wsprintf(msg, "client_bitmap %d", size);
    					send(mySock, msg, strlen(msg), NULL);
    
    					vector<BYTE> data(size);
    
    					memcpy(&data[0], command, strlen(command));
    					int i = strlen(command);
    					memcpy(&data[0+i], pbi, sizeof(BITMAPINFO));
    					i += sizeof(BITMAPINFO);
    					memcpy(&data[0+i], buff, pbi->bmiHeader.biSizeImage);
    
    					send(mySock, (char*)&data[0], size, 0);
    
    					ReleaseDC(hWnd, hDC);
    					DeleteDC(hDC);
    					DeleteObject(hBmp);
    source codes -
    client: http://pastebin.com/ab9vnp8M
    server: http://pastebin.com/4heQvfzs

  11. #26
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,958

    Re: [win32] Send bitmap over socket

    Quote Originally Posted by DaigonoYouso View Post
    I'm totally lost now
    Yes, you are. And your problem is that you're trying to squeeze everything into a single huge function instead of splitting the whole process to several elementary functions responsible for a single particular action each.

    This is what I'd do to split it to phases:
    • Getting HBITMAP - when you get it, you always may test bitmap correctness by just rendering it to some GUI canvas
    • Saving HBITMAP bits to file/stream/buffer - when you get it to file, you always may test its correctness by just opening it with some image viewer
    • Sending bits over socket - when you do that, you always know the size you are to send, and you do that in a single action
    • Reading bits from socket - when you do that, and save the bytes to a file, you always can test it by just file comparison
    • Restoring HBITMAP from bits - see above about getting bitmap

    You see that? With this you are able to control every elementary step of the whole process.

    here's the output from Log function

    http://pastebin.com/h2r3zKR4
    Please note that download links to other resources are not welcomed here.

    and IT IS receiving the right size (5760000), so bitmapinfo is transfered and retrieved fine, I guess, however the bitmap data (or however itis called) is not, since Its drawing a blackscreen (this can also becaused because of the other messages that are getting processed)
    How do you know that? I would say that black screen is an indication of a problem on the most early phase, I'm 99% sure of that. But you are able neither to confirm nor disprove that, because you never followed Paul's advice to save your bitmap to a file. And now you're lost.

    As for the 99% I mentioned. You select your bitmap and never unselect it. You create your compatible DC with NULL. MSDN says:

    hdc [in]

    A handle to an existing DC. If this handle is NULL, the function creates a memory DC compatible with the application's current screen.
    Are you sure this is what you really need?

    You create your compatible bitmap with GetDC(NULL). MSDN says:

    hWnd [in]

    A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire screen.
    Are you sure this is what you really need? Are you sure those compatible things are really compatible ones? Typically the DC got for desktop window becomes a source for creating both, compatible DC and compatible bitmap.

    Bottom line. If I were you, I would immediately stop messing with sending bytes, and get to testing my bitmap generation first of all.

    PS. Saving bitmap to a file or stream can be easily done with ATL::CImage. Is it that you're not able to use it?
    Last edited by Igor Vartanov; January 6th, 2014 at 01:38 PM.
    Best regards,
    Igor

  12. #27
    Join Date
    Oct 2013
    Posts
    39

    Re: [win32] Send bitmap over socket

    This is what I'd do to split it to phases:
    Getting HBITMAP - when you get it, you always may test bitmap correctness by just rendering it to some GUI canvas
    Saving HBITMAP bits to file/stream/buffer - when you get it to file, you always may test its correctness by just opening it with some image viewer
    Sending bits over socket - when you do that, you always know the size you are to send, and you do that in a single action
    Reading bits from socket - when you do that, and save the bytes to a file, you always can test it by just file comparison
    Restoring HBITMAP from bits - see above about getting bitmap
    Im doing that, and I can even draw bitmap created with SetDIBits from that buffer on the client, but not on the server

    Please note that link to other resources are not welcomed here.
    so I had to post 600+ lines here? also everybody knows pastebin...

    How do you know that?
    uhm, because I tested it?

    But you are able neither to confirm nor disprove that, because you never followed Paul's advice to save your bitmap to a file. And now you're lost.
    I did draw it from BITMAPINFO struct and the array of data using SetDIBits on the client side, so no, I confirmed that this is valid, also the struct on the server side was recreated successfully, since header contained the same size as client sent

    Are you sure this is what you really need?
    I did draw it from BITMAPINFO struct and the array of data using SetDIBits on the client side, so no, I confirmed that this is valid
    Bottom line. If I were you, I would immediately stop messing with sending bytes, and get to testing my bitmap generation first of all.
    I did draw it from BITMAPINFO struct and the array of data using SetDIBits on the client side, so no, I confirmed that this is valid
    only if u'd read whole thread...

    PS. Saving bitmap to a file or stream can be easily done with ATL::CImage. Is it that you're not able to use it?
    if I'd want to use MFC or ATL, I'd do it from the start

    As for the 99% I mentioned. You select your bitmap and never unselect it.
    the closest function to release a bitmap is ReleaseDC, which I'm using in case u didn't notice
    Last edited by DaigonoYouso; January 6th, 2014 at 01:44 PM.

  13. #28
    Join Date
    May 2007
    Posts
    800

    Re: [win32] Send bitmap over socket

    Why would anybody help him with that attitude?

  14. #29
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,327

    Re: [win32] Send bitmap over socket

    Quote Originally Posted by STLDude View Post
    Why would anybody help him with that attitude?
    Don't know.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  15. #30
    Join Date
    Oct 2013
    Posts
    39

    Re: [win32] Send bitmap over socket

    Quote Originally Posted by STLDude View Post
    Why would anybody help him with that attitude?
    the only one who helped me was Paul, this Igor just told me to do what I did a long time ago...

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center