[fpc-pascal]Win32 API Call

Michalis Kamburelis michalis at camelot.homedns.org
Thu Jun 24 12:08:17 CEST 2004

Matt Emson wrote:
> It should be boolean. All Win32API return values which are BOOL translate as
> Boolean.
That's not true. WinAPI uses BOOL type, it's defined in WinAPI headers as
   typedef WINBOOL BOOL;

So BOOL is int. So it's 32-bit value on 32-bit systems. Compile this 
simplistic program with any compiler under windows to see that BOOL 
really takes 4 bytes.

   #include <windows.h>
   int main(int argc, char *argv[])
     printf("%d\n", sizeof(BOOL));
     return 0;
   /* output is 4 */

Then, another simplistic program in FPC confirms that LongBool takes 4 
bytes of space and Boolean 1 byte:

    Writeln(SizeOf(LongBool), ' ', SizeOf(Boolean));
   { output is 4 1 }

In FPC Windows unit BOOL type is correctly defined as
   WINBOOL = longbool;

Summing it up: you have to use LongBool (or Windows.Bool) when 
translating WinAPI functions that take or return BOOL type. Boolean is 
not correct, even if it sometimes works.


More information about the fpc-pascal mailing list