Home > other >  Trying to understand structure sizes in the Windows API
Trying to understand structure sizes in the Windows API

Time:12-07

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.

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?

CodePudding user response:

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.

  • Related