views:

208

answers:

3

I tried to translate some new part of winuser.h header to Delphi. Why this structure is expected to be 48 bytes (only this size was accepted by the corresponding function). With 4-bytes boundary, it looks like it should have 40 bytes.

  typedef struct tagGESTUREINFO {
      UINT cbSize;                    
      DWORD dwFlags;                  
      DWORD dwID;                     
      HWND hwndTarget;                
      POINTS ptsLocation;             
      DWORD dwInstanceID;             
      DWORD dwSequenceID;             
      ULONGLONG ullArguments;         
      UINT cbExtraArgs;               
  } GESTUREINFO, *PGESTUREINFO;

If it's related to 8-bytes boundary? if so is it relevant to any case where ULONGLONG appears structures?

Thanks

+10  A: 

The structure is 48 bytes big because the Windows API requires 8-byte alignment. This is simply the convention adopted by Microsoft Windows; MSDN says it's because the largest integral type currently supported is 8 bytes big, so 8-byte alignment ensures that all integral types are properly aligned.

(Keep in mind that header files such as winuser.h specify an API, but to actually use an already-compiled library using that API, you need an ABI, which includes details like calling conventions and structure alignment.)

Josh Kelley
+4  A: 

Yes, it is the default packing of 8 which moves the ullArgument member up to get it aligned properly. There are 4 padding bytes there to get it from offset 28 to 32. And 4 padding bytes at the end to ensure that an array of structures still has that member aligned properly.

Hans Passant
+3  A: 

Note that this type is defined in the Delphi 2010 Windows.pas already.

Giel
Yes, I know, but I manage to do this for a much much earlier version
Maksee