Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to access BITMAP bmBits - getting void* - unknown size error .

How to access BITMAP bmBits - getting void* - unknown size error .

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsdata-structurestutorial
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • V 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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      V G 3 Replies Last reply
      0
      • L Lost User

        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.

        V Offline
        V Offline
        Vaclav_
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • V 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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Vaclav_Sal wrote:

          the LPVOID pointer could have been just char *

          Yes but I think this is to allow a general structure which can contain a pointer to any format of bitmap in the future and not just a simple BYTE array.

          It's time for a new signature.

          1 Reply Last reply
          0
          • L Lost User

            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.

            G Offline
            G Offline
            garaber
            wrote on last edited by
            #5

            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

            L 1 Reply Last reply
            0
            • G garaber

              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

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Sorry, I'm not sure I understand your question.

              I must get a clever new signature for 2011.

              G 1 Reply Last reply
              0
              • L Lost User

                Sorry, I'm not sure I understand your question.

                I must get a clever new signature for 2011.

                G Offline
                G Offline
                garaber
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • L Lost User

                  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.

                  G Offline
                  G Offline
                  garaber
                  wrote on last edited by
                  #8

                  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

                  L 1 Reply Last reply
                  0
                  • G garaber

                    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

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    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 numbers

                    In 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.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups