mingw-w32 incorrectly declares HBRUSH.

by (Login MCalkins)
C-Forum

 

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

Posted on Jul 29, 2012, 8:33 PM

Respond to this message   

Return to Index

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement