How to access BITMAP bmBits - getting void* - unknown size error .
-
I am trying to access BITMAP bmBits and I can get the first member of the BYTE array. Sort off, I am not sure if it is the real value of the color. However, when I try to increment the pointer I get “unknown size of void*” error. The bmBits member of BITMAP is declared (standard) as LPVOID and should point to array of bytes.The BITMAP structure was filled using (HBITMAP)GetClipboardData(CF_BITMAP). Could someone please explain to me what am I missing here and how to fix it. This works: BYTE bmp = (BYTE) pDoc->bitmap[iBITMAP].bmBits; And this code gives me the void* error bmpBYTE = (BYTE) pDoc->bitmap[iBITMAP].bmBits++; Any constructive help is as always appreciated. Thanks for reading, Vaclav
-
I am trying to access BITMAP bmBits and I can get the first member of the BYTE array. Sort off, I am not sure if it is the real value of the color. However, when I try to increment the pointer I get “unknown size of void*” error. The bmBits member of BITMAP is declared (standard) as LPVOID and should point to array of bytes.The BITMAP structure was filled using (HBITMAP)GetClipboardData(CF_BITMAP). Could someone please explain to me what am I missing here and how to fix it. This works: BYTE bmp = (BYTE) pDoc->bitmap[iBITMAP].bmBits; And this code gives me the void* error bmpBYTE = (BYTE) pDoc->bitmap[iBITMAP].bmBits++; Any constructive help is as always appreciated. Thanks for reading, Vaclav
A void pointer can be used to point to anything, but the compiler cannot calculate an increment size for it as there is no way of knowing what it will point to at run time. You just need to create a
BYTE
pointer to this array, cast the void pointer to it and use that to iterate through it thus:PBYTE pBmBits = (PBYTE) pDoc->bitmap[iBITMAP].bmBits;
bmpBYTE = *pBmBits++;
...It's time for a new signature.
-
A void pointer can be used to point to anything, but the compiler cannot calculate an increment size for it as there is no way of knowing what it will point to at run time. You just need to create a
BYTE
pointer to this array, cast the void pointer to it and use that to iterate through it thus:PBYTE pBmBits = (PBYTE) pDoc->bitmap[iBITMAP].bmBits;
bmpBYTE = *pBmBits++;
...It's time for a new signature.
Thank you for your explanation. Now I know more ( about casts) and therefore I am more dangerous to myself. I guess in the case of BITMAP the LPVOID pointer could have been just char * since it points to byte array anyway. But it makes it more challenging for weekend programmers like me. Thanks again Vaclav
-
Thank you for your explanation. Now I know more ( about casts) and therefore I am more dangerous to myself. I guess in the case of BITMAP the LPVOID pointer could have been just char * since it points to byte array anyway. But it makes it more challenging for weekend programmers like me. Thanks again Vaclav
-
A void pointer can be used to point to anything, but the compiler cannot calculate an increment size for it as there is no way of knowing what it will point to at run time. You just need to create a
BYTE
pointer to this array, cast the void pointer to it and use that to iterate through it thus:PBYTE pBmBits = (PBYTE) pDoc->bitmap[iBITMAP].bmBits;
bmpBYTE = *pBmBits++;
...It's time for a new signature.
-
what if you wanted to put this in to a bitfield. I have a bit map that has one bit per pixel and measures 7x70
-
Sorry, I'm not sure I understand your question.
I must get a clever new signature for 2011.
I have a binary (monochrome) bitmap that is 70x7 pixels would like to put it in an array that is 70x7 as binary. I know that bit fields would be a good choice. ie: struct { unsigned byte d0:1; unsigned byte d1:1; unsigned byte d2:1; unsigned byte d3:1; .... } test
-
A void pointer can be used to point to anything, but the compiler cannot calculate an increment size for it as there is no way of knowing what it will point to at run time. You just need to create a
BYTE
pointer to this array, cast the void pointer to it and use that to iterate through it thus:PBYTE pBmBits = (PBYTE) pDoc->bitmap[iBITMAP].bmBits;
bmpBYTE = *pBmBits++;
...It's time for a new signature.
how would you cast this pointer to a bit field? ie: struct 7bitfield { unsigned byte d0:1; unsigned byte d1:1; unsigned byte d2:1; unsigned byte d3:1; unsigned byte d4:1; unsigned byte d5:1; unsigned byte d6:1; } 7bits; The reason for asking is I have an monochrome bitmap that is 70x7 and need to retrieve the data as an array of 1's and 0's. These will be used to control the on/off state of an led display. Thanks
-
how would you cast this pointer to a bit field? ie: struct 7bitfield { unsigned byte d0:1; unsigned byte d1:1; unsigned byte d2:1; unsigned byte d3:1; unsigned byte d4:1; unsigned byte d5:1; unsigned byte d6:1; } 7bits; The reason for asking is I have an monochrome bitmap that is 70x7 and need to retrieve the data as an array of 1's and 0's. These will be used to control the on/off state of an led display. Thanks
Are you saying that the fields are packed, such that the second field starts at the last bit of the byte containing the first field and so on? Something like:
byte0 + byte1 + byte2 +
01234567|01234567|01234567|01234567
01234560123456012345601234560123
00000001111111222222233333334444 - pixel numbersIn this case you would probably need to use a
BYTE
pointer and adjust it manually as you traverse the array.I must get a clever new signature for 2011.