Archived

This topic is now archived and is closed to further replies.

yckx

help understanding windows structs

Recommended Posts

Windows seems to be full of structs like these: typedef struct _WNDCLASSEX { //yadda //yadda } WNDCLASSEX; typedef struct tagPAINTSTRUCT { //yadda //yadda } PAINTSTRUCT; I don''t understand what _WNDCLASSEX and tagPAINTSTRUCT are. Can someone clear this up for me? Thanks yckx

Share this post


Link to post
Share on other sites
In C++, you declare a struct like this:


  
struct MyStruct {
int thing1;
int thing2;
};


In C you do it differently however, like this:


  
typedef struct tagMyStruct {
int thing1;
int thing2;
} MyStruct;


Maybe this will help you determine the difference between the two. Let''s assume you declared a struct in C without the end part, so it''s basically the same as the C++ version.


  
struct MyStruct {
int thing1;
int thing2;
};


Now, to declare a struct in a C++ program you do:

MyStruct ms1;

But in C, you would have to do this:

struct MyStruct ms1;

You have to add the extra "struct" to the declaration. That''s kind of annoying, so what people do is this:


  
struct MyStruct {
int thing1;
int thing2;
};

typedef struct MyStruct MyCoolStruct;

// Now you can declare it like normal, for example...


MyCoolStruct mcs1;


I assume you understand how typedef works. If not, speak up.

So basically all people do is make that who thing into one line, and put the typedef and the struct together instead of doing it on seperate lines, so you have:


  
typedef struct tagMyStruct {
int thing1;
int thing2;
} MyStruct;


And now you can declare a struct "normally". Hope this helps. If not, tell us what you are having trouble understanding.

Russell

Share this post


Link to post
Share on other sites
Ahh~~! Thank you. I started learning c++ without delving into c first, so I''m not familiar with many of the differences between the two, such as struct definitions. I didn''t have a problem using the Win API structs, I just didn''t understand the syntax I was seeing. So it''s basically a c-style shortcut.

Thanks for the help.

yckx

Share this post


Link to post
Share on other sites