News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Purpose Of Structure Size Element

Started by raleep, December 14, 2012, 03:31:44 PM

Previous topic - Next topic

raleep

The PRINTDLG structure contains 19 elements, all DWords except for 5 Words, for a total of 66 bytes.

The first element is DWord lStructSize, the structure size, in bytes.

Am I correct in inferring that this may (and for the sake of efficiency should) be set to 34, not 66, if the last 8 DWords are all made irrelevant by flag settings?

Thanks, ral

qWord

Quote from: raleep on December 14, 2012, 03:31:44 PMAm I correct in inferring that this may (and for the sake of efficiency should) be set to 34, not 66, if the last 8 DWords are all made irrelevant by flag settings?
no, you must use the size of your definition (SIZEOF PRINTDLG). The purpose of the size field in API structures is that it makes possible to extend the structure in future OS versions. (if you take a look in the SDK headers, you will find in many structure definitions with conditional preprocessor statements that relies on the selected target  OS).
MREAL macros - when you need floating point arithmetic while assembling!

CommonTater

Quote from: qWord on December 14, 2012, 04:03:29 PM
The purpose of the size field in API structures is that it makes possible to extend the structure in future OS versions.

That... and the possible difference in data alignment between 32 and 64 bit software.  It needs the actual size of the struct in memory.

MichaelW

The size needs to match the size that the Microsoft compilers return, which for the structures from the 2003 PSDK is 66 bytes. For the structures from the current MASM32 windows.inc the MASM SIZEOF returns 66, but at least in the past there have been structures where the returned size did not match that of the Microsoft compilers.
Well Microsoft, here's another nice mess you've gotten us into.

raleep

Quote from: qWord on December 14, 2012, 04:03:29 PM
Quote from: raleep on December 14, 2012, 03:31:44 PMAm I correct in inferring that this may (and for the sake of efficiency should) be set to 34, not 66, if the last 8 DWords are all made irrelevant by flag settings?
no, you must use the size of your definition (SIZEOF PRINTDLG). The purpose of the size field in API structures is that it makes possible to extend the structure in future OS versions. (if you take a look in the SDK headers, you will find in many structure definitions with conditional preprocessor statements that relies on the selected target  OS).

I see.  So if I used 34 it would likely crash, if I used 66 it would be a pain to upgrade if the value were changed, while using SIZEOF PRINTDLG all I'd need to do is reassemble with an updated assembler.

Thanks.

An afterthought:

I still feel this is poor strategy: the OS always knows what it needs; so why burden the programmer?

dedndave

the function checks the size member
if it is not one of the valid size values, it will return an error, something like invalid parameter
it uses the structure size for 2 things, i suppose
one is to verify you have a proper structure
but, more importantly, it uses the structure size as a "structure version number"
for some functions, you can call them with older or newer structure definitions, and it will work
it knows which definition you are using by the size
for some functions, the size must be a specific value, and may vary with os version, etc

qWord

Quote from: CommonTater on December 14, 2012, 05:10:29 PM
Quote from: qWord on December 14, 2012, 04:03:29 PM
The purpose of the size field in API structures is that it makes possible to extend the structure in future OS versions.

That... and the possible difference in data alignment between 32 and 64 bit software.  It needs the actual size of the struct in memory.
that doesn't required a size field because the alignment is fixed for each platform.
MREAL macros - when you need floating point arithmetic while assembling!