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

Trying to understand structure sizes in the Windows API

I’m looking for building an application using the Windows API.
I’m using Go, which can used to interact with the Windows API (by using the syscall package), however, that’s unimportant for this question.

I’m looking at the API to register a new Sync Root, and that’s done using the function CfRegisterSyncRoot.

According to this method’s signature, it accepts an CF_SYNC_REGISTRATION but here I find some information which confuses me.

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

According to the definition, this function has a field named StructSize which represents the size of the structure, but I don’t find any more information regarding this.
What am I supposed to pass in here?

>Solution :

The documentation you linked to says the StructSize member is the "The size of the structure.". That means it is the number of bytes used to store the structure in memory. You can get the right value by evaluating sizeof(CF_SYNC_REGISTRATION) in a C compiler, and you should write this value into the StructSize member before you pass it to a Windows API function.

This kind of thing is common in the Windows API. I think this is a mechanism that allows Windows to occasionally add new members to their structs, without breaking compatibility with old code that doesn’t know about the new members.

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