Respond to this messageReturn to Index
Original Message
  • mingw-w32 incorrectly declares HBRUSH.
    • (Login MCalkins)
      C-Forum
      Posted Jul 29, 2012 8:33 PM

      Using the version of mingw-w32 that comes with QB64 0.954:


      #include "windows.h"
      #include "stdio.h"

      int main(void) {
      printf("0x%x\n", (void *) 0 + 1);
      printf("0x%x\n", (PVOID) 0 + 1);
      printf("0x%x\n", (HANDLE) 0 + 1);
      printf("0x%x\n", (HBRUSH) 0 + 1);
      return 0;
      }

      --------------------------------------------------------------------------------

      C:\c>\q\qb64\internal\c\bin\g++ -Wl,-Map,delme.map delme.cpp -o delme.exe
      delme.cpp: In function 'int main()':
      delme.cpp:5:32: warning: pointer of type 'void *' used in arithmetic [-Wpointer-
      arith]
      delme.cpp:6:31: warning: pointer of type 'void *' used in arithmetic [-Wpointer-
      arith]
      delme.cpp:7:32: warning: pointer of type 'void *' used in arithmetic [-Wpointer-
      arith]

      C:\c>delme
      0x1
      0x1
      0x1
      0x4

      C:\c>

      --------------------------------------------------------------------------------

      I discovered this in trying to set the hbrBackground member of a WNDCLASSA structure. When specifying a system color, you are supposed to add 1 to the constant. To overcome an error from mingw-w32, (something like this:)

      error: invalid conversion from 'int' to 'HBRUSH {aka HBRUSH__*}' [-fpermissive]

      I used an explicit cast to HBRUSH, but the cast had higher precedence than the addition, and I had forgotten to use parenthesis. So it silently added 4 instead of 1.

      according to the MSDN documentation, windef.h is supposed to do this:

      typedef HANDLE HBRUSH;

      but the mingw-w32 windef.h does this:

      DECLARE_HANDLE(HBRUSH);

      So, remember to use parenthesis around the +1.

      Regards,
      Michael
    Your Name
    Your Email
    (Optional)
    Message Title
    Message Text
    Image Services Photobucket.com
    Options Enable formatted text (Huh?)
    Also send responses to my email address