QB64 Phoenix Edition
API Questions - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10)
+---- Thread: API Questions (/showthread.php?tid=1918)

Pages: 1 2 3


RE: API Questions - a740g - 08-20-2023

(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.


RE: API Questions - SMcNeill - 08-20-2023

(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?


RE: API Questions - a740g - 08-20-2023

Also, all elements should be at the correct offset (including the padding).


RE: API Questions - a740g - 08-20-2023

(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.


RE: API Questions - SpriggsySpriggs - 08-20-2023

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.