API Questions
#21
(08-20-2023, 06:15 PM)Jack Wrote: with all due respect to a740g, I am not comfortable with the padding in MENUITEMINFO
this C code prints 80 as the size of MENUITEMINFO
Code: (Select All)
#include <stdio.h>
#include <windows.h>
#include <winuser.h>

int main(void){
printf("%lld\n", sizeof(MENUITEMINFO));
return 0;
}
80 is correct.

Quote:Len of MENUITEMINFO = 80
sizeof(MENUITEMINFO) = 80
Steve is correct. Without the padding it will be far less than 80 and crash.
Reply
#22
(08-20-2023, 06:15 PM)Jack Wrote: with all due respect to a740g, I am not comfortable with the padding in MENUITEMINFO
this C code prints 80 as the size of MENUITEMINFO
Code: (Select All)
#include <stdio.h>
#include <windows.h>
#include <winuser.h>

int main(void){
printf("%lld\n", sizeof(MENUITEMINFO));
return 0;
}
TYPE MENUITEMINFO
    AS _UNSIGNED LONG cbSize   4
    AS _UNSIGNED LONG fMask    8
    AS _UNSIGNED LONG fType    12
    AS _UNSIGNED LONG fState    16
    AS _UNSIGNED LONG wID    20
    AS STRING * 4 __padding1    24
    AS _UNSIGNED _OFFSET hSubMenu    32
    AS _UNSIGNED _OFFSET hbmpChecked    40
    AS _UNSIGNED _OFFSET hbmpUnchecked    48
    AS _UNSIGNED _OFFSET dwItemData    56
    AS _UNSIGNED _OFFSET dwTypeData ' str ptr    64
    AS _UNSIGNED LONG cch    68
    AS STRING * 4 __padding2    72
    AS _UNSIGNED _OFFSET hbmpItem    80
END TYPE


What's wrong with it?
Reply
#23
Also, all elements should be at the correct offset (including the padding).
Reply
#24
(08-20-2023, 05:47 PM)TerryRitchie Wrote:
(08-20-2023, 12:01 AM)a740g Wrote: Here. This should work on 64-bit compilers.

Yes it does, thank you! This example should be added to the Windows Library examples in the Wiki.

Could you explain the changes you made and why they needed to be done so I can get a better understanding of your code and why 64-bit needs to be approached differently please?

I actually use the caveman's method. Big Grin At least that's what I call it. But it works.

I've attached source files that you can use to figure out stuff like these. Note that the results will be different on 32-bit and 64-bit compilers. But you should be able to cover both cases using the QB64 $IF metacommand.


Attached Files
.zip   type_padding.zip (Size: 832 bytes / Downloads: 12)
Reply
#25
I find that using OFFSETOF in a header helps quite a bit with making sure each type member is the right size and in the right position.
Ask me about Windows API and maybe some Linux stuff
Reply




Users browsing this thread: 3 Guest(s)