Recent

Author Topic: shlobj.pp SHELLFLAGSTATE definition problem  (Read 2219 times)

440bx

  • Hero Member
  • *****
  • Posts: 6149
shlobj.pp SHELLFLAGSTATE definition problem
« on: August 02, 2025, 11:35:05 pm »
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)

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18787
  • To Europe: simply sell USA bonds: dollar collapses
Re: shlobj.pp SHELLFLAGSTATE definition problem
« Reply #1 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.
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.
« Last Edit: August 03, 2025, 12:12:28 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

PascalDragon

  • Hero Member
  • *****
  • Posts: 6355
  • Compiler Developer
Re: shlobj.pp SHELLFLAGSTATE definition problem
« Reply #2 on: August 03, 2025, 01:16:47 pm »
The C definition is definitely wrong. You should not use BOOL instead of a ULong for bitfield containers of size 4.

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

  • Hero Member
  • *****
  • Posts: 18787
  • To Europe: simply sell USA bonds: dollar collapses
Re: shlobj.pp SHELLFLAGSTATE definition problem
« Reply #3 on: August 03, 2025, 02:07:20 pm »
Which is word since 16 bit windows....
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

440bx

  • Hero Member
  • *****
  • Posts: 6149
Re: shlobj.pp SHELLFLAGSTATE definition problem
« Reply #4 on: August 03, 2025, 02:40:54 pm »
Which is word since 16 bit windows....
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.)

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18787
  • To Europe: simply sell USA bonds: dollar collapses
Re: shlobj.pp SHELLFLAGSTATE definition problem
« Reply #5 on: August 03, 2025, 05:24:02 pm »
In this case I would leave it as is.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

PascalDragon

  • Hero Member
  • *****
  • Posts: 6355
  • Compiler Developer
Re: shlobj.pp SHELLFLAGSTATE definition problem
« Reply #6 on: August 05, 2025, 10:22:00 pm »
Which is word since 16 bit windows....

BOOL is declared as typedef int BOOL in WinDef.h and on 32-bit (and 64-bit) systems int is 32-bit.

What is defined smaller is BOOLEAN, but that is defined as typedef BYTE BOOLEAN (in WinNT.h), so it's 8-bit.

In this case I would leave it as is.

No, because that makes the record's declaration broken compared to the C struct's declaration.

 

TinyPortal © 2005-2018