Problem with DLGTEMPLATE structure

Started by MichaelW, January 23, 2009, 04:03:17 PM

Previous topic - Next topic

MichaelW

There is a problem with the DLGTEMPLATE structure definition in windows.inc:

DLGTEMPLATE STRUCT DWORD
  style             DWORD      ?
  dwExtendedStyle   DWORD      ?
  cdit              WORD      ?
  x                 WORD      ?
  y                 WORD      ?
  lx                WORD      ?
  ly                WORD      ?
DLGTEMPLATE ENDS


The DWORD alignment is causing ML to pad the length to a multiple of the alignment, instead of the 18 bytes that it is supposed to be.
eschew obfuscation

ToutEnMasm

Hello,
Perhaps this will answer your question
Quote
;/*
; * WARNING:
; * The following structures must NOT be DWORD padded because they are
; * followed by strings, etc that do not have to be DWORD aligned.
; */
;Include pshpack2.SDK
;/*
; * original NT 32 bit dialog template:
; */

DLGTEMPLATE   STRUCT
   style DWORD ?
   dwExtendedStyle DWORD ?
   cdit WORD ?
   x WORD ?
   y WORD ?
   regcx WORD ?
   cy WORD ?
DLGTEMPLATE      ENDS


pshpack2 give a word alignment




MichaelW

The problem is with the length of the structure, not with the alignment of the three WORD arrays that must follow the structure. These arrays need to be WORD aligned, and since the structure must be DWORD aligned this alignment will be satisfied whether the length of the structure is 20 bytes or 18 bytes. If the structure is padded to 20 bytes, the system assumes the padding is the first WORD array, and the three WORD arrays that follow are one too many, and unless the dialog has no controls there will be a problem with the first DLGITEMTEMPLATE structure.
eschew obfuscation

dedndave

making this change has the possible side-effect of breaking some code

fortunately, i do not see it being referenced in any masm32 lib functions or examples   :bg

MichaelW

It's been a while, but if I recall correctly this problem does not affect the MASM32 in-memory dialog macros because they do not depend on the length of the structure, so correcting the problem should have no adverse effect there, but I don't recall actually testing this. This problem showed up in the in-memory dialog system that I did for GeneSys because I depended on the size of the structure.

    ;---------------------------------------------
    ; Initialize lpw and adjust it so it points
    ; to the next WORD following the structure.
    ;---------------------------------------------

    mov lpw, eax
    add lpw, SIZEOF _DLGTEMPLATE


And the solution was simply to include a corrected and renamed structure.
eschew obfuscation

dedndave

well - i corrected the one in my windows.inc file
not many programs use it
as far as i can see, the masm32 in-memory dialog macros do not use it, either

it could break some code that was incorrectly written...
code that happens to work because there are extra zeros at the end of the structure/array data area
by removing the dword alignment, those zeros will be gone

but, it is really necessary to fix it if you want to place additional controls following the dialog structure

as it turns out, i am not using the structure, as i am building the data area on the stack   :P

MichaelW

My primary goal was to make the code easy to understand, and to accomplish that I needed to follow the Microsoft references closely and take a more high-level approach. My system uses procedures to build the templates, instead of macros or raw assembly code.
eschew obfuscation