Phix: get_struct_size() returns eventually wrong size
- Posted by andreasWagner Sep 26, 2023
- 906 views
Hallo With Phix version 1.0.3 get_struct_size() returns eventually wrong size. It seems to happen with the WORD Datatype.
I have put togheter this example:
include cffi.e constant tPD=""" typedef struct tagPD { DWORD lStructSize; HWND hwndOwner; HGLOBAL hDevMode; HGLOBAL hDevNames; HDC hDC; DWORD Flags; WORD nFromPage; WORD nToPage; WORD nMinPage; WORD nMaxPage; WORD nCopies; HINSTANCE hInstance; LPARAM lCustData; LPPRINTHOOKPROC lpfnPrintHook; LPSETUPHOOKPROC lpfnSetupHook; LPCTSTR lpPrintTemplateName; LPCTSTR lpSetupTemplateName; HGLOBAL hPrintTemplate; HGLOBAL hSetupTemplate; } PRINTDLG, *LPPRINTDLG; """ global constant integer idPD=define_struct(tPD) global atom pPD=allocate_struct(idPD) printf(1,"Size of struct : %d should be 66",get_struct_size(idPD)) set_struct_field(idPD,pPD,"let_it_crash",0)
Output:
Size of struct : 68 should be 66 D:\devpool\phix\builtins\cffi.e:1128 in procedure set_struct_field() index 0 out of bounds, reading sequence length 19 id = 1 pStruct = 10122496.0 field = "let_it_crash" v = 0 membernames = {"lStructSize","hwndOwner","hDevMode","hDevNames","hDC","Flags","nFromPage","nToPage","nMinPage","nMaxPage","nCopies","hInstance","lCustData","lpfnPrintHook","lpfnSetupHook","lpPrintTemplateName","lpSetupTemplateName","hPrintTemplate","hSetupTemplate"} details = {{"DWORD",4,0,0},{"HWND",4,4,1},{"HGLOBAL",4,8,1},{"HGLOBAL",4,12,1},{"HDC",4,16,1},{"DWORD",4,20,0},{"WORD",2,24,1},{"WORD",2,26,1},{"WORD",2,28,1},{"WORD",2,30,1},{"WORD",2,32,1},{"HINSTANCE",4,36,1},{"LPARAM",4,40,1},{"LPPRINTHOOKPROC",4,44,1},{"LPSETUPHOOKPROC",4,48,1},{"LPCTSTR",4,52,1},{"LPCTSTR",4,56,1},{"HGLOBAL",4,60,1},{"HGLOBAL",4,64,1}} k = 0 size = <novalue> offset = <novalue> ... called from D:\devpool\phix\demo\edita\tinewg\cffi_test.exw:33
Thank you Andreas