Author Topic: are you sure that 4+4+1=9 ?  (Read 10171 times)

jj2007

  • Member
  • *****
  • Posts: 10446
  • Assembler is fun ;-)
    • MasmBasic
Re: are you sure that 4+4+1=9 ?
« Reply #15 on: September 07, 2012, 08:08:29 PM »
There are a number of options, see snippet below for testing. The question is which size the API expects if it throws an error.

Code: [Select]
include \masm32\include\masm32rt.inc

STORAGE_PROPERTY_QUERY STRUCT ;DWORD
  PropertyId DWORD ?
  QueryType DWORD ?
  AdditionalParameters BYTE ?
;  manual_padding db (DWORD-1) dup(?)
STORAGE_PROPERTY_QUERY ENDS

.code
spq STORAGE_PROPERTY_QUERY <>
dummy dd ?

start: mov eax, offset dummy
sub eax, offset spq
print str$(eax), " bytes in memory", 13, 10
print str$(sizeof spq), " size of spq", 13, 10
print str$(sizeof STORAGE_PROPERTY_QUERY), " size of STORAGE_PROPERTY_QUERY", 13, 10
print str$(STORAGE_PROPERTY_QUERY), " STORAGE_PROPERTY_QUERY", 13, 10
inkey " "
exit

end start

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: are you sure that 4+4+1=9 ?
« Reply #16 on: September 07, 2012, 08:23:36 PM »
There won't always be an error reported. Sometimes the misalignment will just cause a hard to diagnose problem. I think the only reasonable and reliable way around this problem is to check each structure definition against a Microsoft compiler and header file.

Well Microsoft, here’s another nice mess you’ve gotten us into.

TouEnMasm

  • Member
  • *****
  • Posts: 1290
    • EditMasm
Re: are you sure that 4+4+1=9 ?
« Reply #17 on: September 08, 2012, 10:18:04 PM »
I have modified the "ready to use sdk" (windows.inc subforum).
Now he give the same alignment to the structures than the c++.
If it is not enough,PARTITION_INFORMATION  seem to be a special case,the defaut alignment of DWORD can be change to QWORD in the translate.inc file.

Quote
   ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
   DefaultAlignement equ <DWORD>
   DEFALIGNMASM TEXTEQU  DefaultAlignement
   ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
change to
Quote
   ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
   DefaultAlignement equ <QWORD>
   DEFALIGNMASM TEXTEQU  DefaultAlignement
   ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
and all the structures with no alignment specify are qword align
Specified alignment can be BYTE,WORD,DWORD or QWORD.





« Last Edit: September 11, 2012, 03:24:23 AM by ToutEnMasm »
Fa is a musical note to play with CL