Sign in to follow this  
Waaayoff

A simple Win32 question?

Recommended Posts

Rattrap    3385

WNDCLASSEX WndClassEx;
WndClassEx.cbSize = sizeof(WNDCLASSEX);





[edit] - Sorry I read too fast :)

A lot of the Microsoft stuctures do this. I think this is kind of a weird form of versioning in their code behind the scenes. I think it also is because most structures are passed by pointer, so it is hard to tell what was actually passed and how big it really is.

[Edited by - Rattrap on February 12, 2010 8:36:05 AM]

Share this post


Link to post
Share on other sites
MJP    19786
Quote:
Original post by Rattrap
I think this is kind of a weird form of versioning in their code behind the scenes.


Yes this is exactly it. The functions uses it to know which version of the Windows SDK the program was compiled with, so that it knows what behavior to use. This way when Microsoft adds new functionality to a function they can make the struct bigger, and older programs using smaller struct size will get the behavior they expect (which keeps them from crashing).

Share this post


Link to post
Share on other sites
Anon Mike    1098
There's nothing particularly wierd about it. API's evolve over time. Microsoft wants to be able to do that without having to create a new version of the API every single time. Introducing new API's also makes it harder for developers to adopt them because their programs won't work at all on older systems without special care. Having a size field is in some ways simpler than a version field and it's easy/effiecient to get the size so why not.

WNDCLASSEX is actually an excellent example. If the original structure (WNDCLASS) had had the size field they wouldn't have had to create the RegisterClassEx API. Programs would just set the size to whatever they knew about and call the single API.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this