Working with MSDN

Hello all, just looking for some help understanding the beginning and end of this description. It's a typical example of what i see looking at the WINAPI and DX documentation and want to make sure I understand it.

As i read it, tagWNDCLASSEX is a typedef (renaming) of the struct WNDCLASSEX (because WNDCLASSEX immediate follows the {}braces). If that is correct, what does the pointer at the end represent?

Thanks in advance.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
typedef struct tagWNDCLASSEX {
  UINT      cbSize;
  UINT      style;
  WNDPROC   lpfnWndProc;
  int       cbClsExtra;
  int       cbWndExtra;
  HINSTANCE hInstance;
  HICON     hIcon;
  HCURSOR   hCursor;
  HBRUSH    hbrBackground;
  LPCTSTR   lpszMenuName;
  LPCTSTR   lpszClassName;
  HICON     hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;
This style is common because C is weird with struct namespaces.

In C, a struct name must be prefixed with 'struct' or else it will not be recognized:

1
2
3
4
5
6
7
struct Foo
{
  //...
};

Foo a;  // Error:  'foo' not defined
struct Foo b;  // OK 


To get around this... C coders often typedef their struct names to another (or the same) struct name just to get it in the global namespace so you don't have to prefix it with the 'struct' keyword whenever you want to use it.

1
2
3
4
5
6
7
8
struct Foo
{
  //...
};

typedef struct Foo Bar;

Bar a;  // OK.  Same as saying "struct Foo a;" 


Furthermore, you can typedef a pointer the same way:

1
2
3
4
5
typedef struct Foo* Ptr;

Ptr p;  // OK... same as saying "struct Foo* p;"
   // or "Bar* p;"
   //   ie:  it creates a pointer to a struct 



What MSDN is doing is shortcutting all of that by putting in all the same statement:

This:
1
2
3
typedef struct tagWNDCLASSEX{
  //...
} WNDCLASSEX, *PWNDCLASSEX;

is the same as this:
1
2
3
4
5
6
struct tagWNDCLASSEX{
  //...
};

typedef struct tagWNDCLASSEX WNDCLASSEX;
typedef WNDCLASSEX* PWNDCLASSEX;
Last edited on
Thanks for the explanation!
Topic archived. No new replies allowed.