Correction to DLGITEMTEMPLATEEX Structure

This wasted several hours for me this morning. The MSDN docs for DLGITEMTEMPLATEEX are wrong: there is an extra WORD member after the id member, call it reserved.

Note that this struct is not in any windows header: you are expected to cut & paste it into your code. (Always a good idea...)

I am grokking dialog templates, and what fun it is. Raymond has already described in great detail the evolution of these crazy structures, and if you look carefully you will see that he thinks the id member is a DWORD. I took a look at the Windows source code and in fact the id is a WORD, but there is an unused word after it. (The Windows tree itself contains a bunch of definitions of this type, because it isn't in the internal headers either, and all but one have ID as a DWORD).

Once thing that Raymond doesn't explicitly call out is the subtle change in the extra byte count compared to DLGITEMTEMPLATE - for the former MSDN says the size (when non-zero) includes the WORD itself. For the latter it makes no such claims. Interestingly I found both algorithms in a few places in the Windows tree that handles this extra byte counts, so I'm not even sure how they should be treated. As my dialogs have yet to have this member non-zero, I'm not caring right now.

Comments (3)
  1. um, no, it’s a 32-bit DWORD in the dialog manager. You read the code wrong.

  2. Andy says:

    I couldn’t actually find it in the dialog manager as the struct has a different name there. For defensive coding, I am going to use a WORD for the id and a WORD of unused, even if Windows treats it as a DWORD: I saw weird values on the examples so WORD is safe for me.

  3. capn skarz says:

    I’ve seen dialogs in EXEs (presumably compiled with a Microsoft compiler) that when the id was FFFF so was the extra word after, which would lead me to believe it was treated like a DWORD. Luckily ignoring that extra word still doesn’t change the value in that case.

Comments are closed.

Skip to main content