Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why do many Win32 Strucs contain their size as a member

This is not strictly a programming question but more of a design question.

Working with some strucs from the WinAPI I noticed that many of them contain a field called dwSize that simpally stores their size e.g THREADENTRY32 or BLUETOOTH_DEVICE_SEARCH_PARAMS

typedef struct tagTHREADENTRY32 {
DWORD dwSize;
DWORD cntUsage;
DWORD th32ThreadID;
DWORD th32OwnerProcessID;
LONG  tpBasePri;
LONG  tpDeltaPri;
DWORD dwFlags;
} THREADENTRY32;

Thinking about this design i find it intriguing why can’t the code that using those structures use sizeof?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is the actual thinking behind this?

>Solution :

This is to support future versions of that structure that might have new fields added to it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading