Forum > Windows

shlobj.pp SHELLFLAGSTATE definition problem

(1/2) > >>

440bx:
Hello,

In shlobj.pp, SHELLFLAGSTATE is defined as a word which means the structure is of size 2. 

The C definition uses type BOOL to define the bit fields, resulting in a size of 4 (in Win32 and Win64) (NOTE: size verified in C and C++ in both 32 and 64 bits)

Thaddy:
The C definition is definitely wrong. You should not use BOOL instead of a ULong for bitfield containers of size 4.
From the looks of it there are no flags using the hiword, so word seems OK. In this case a redefinition would not hurt, though.
(btw, C's ULong is also 32 bit on 64 bit platforms. Like cardinal, modern C that is.)
Maybe it is a remnant of 16 bit Windows, because there BOOL is 2 bytes. Looks funny anyway.
When I ask CoPilot "Can you explain why microsoft use BOOL for the SHELLFLAGSTATE container? in shlobj? looks wrong."
it confirms my hunch.

Then I asked "No, just that Freepascal translates it as word, which seems correct since the hiword is never used."
And the asnwer is:(excerpt)
"Exactly—and that makes Free Pascal’s choice more elegant and efficient in this case.

"Since SHELLFLAGSTATE only uses bitfields in the low word, defining the container as a WORD is perfectly sensible. There's no meaningful use of the high word, so Microsoft's use of BOOL just adds unnecessary bulk. It’s one of those “just because we’ve always done it that way” situations you find often in legacy C headers.".
So if anything C is wrong. Pascal is corrrect.

PascalDragon:

--- Quote from: Thaddy on August 03, 2025, 09:19:10 am ---The C definition is definitely wrong. You should not use BOOL instead of a ULong for bitfield containers of size 4.
--- End quote ---

If the official Microsoft Windows SDK headers say it's a BOOL then it is a BOOL and thus a 32-bit unsigned value no no matter what you say or some smartass probabilistic word chain generator say. And a list of bitfields in a struct in C or C++ always lead to the struct at least having the size of the underlying base type.

Thaddy:
Which is word since 16 bit windows....

440bx:

--- Quote from: Thaddy on August 03, 2025, 02:07:20 pm ---Which is word since 16 bit windows....

--- End quote ---
You need to let the compiler know that, because right now, in Win32 and Win64 it says it's size 4 but, of course, you are "right" and  the C/C++ compiler is "wrong" (everybody knows that.)

Navigation

[0] Message Index

[#] Next page

Go to full version