I’m going through many examples of basic win32 dialog procedures. They seem to take this basic pattern.
class Person
{
char Name[63];
int Age;
};
BOOL CALLBACK EditDlgProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static Person* person;
switch(uMsg)
{
case WM_INITDIALOG:
person = (Person*)lParam;
return FALSE;
case WM_COMMAND:
.....
}
return FALSE;
}
I want to know why make person static?
- Is this for efficiency? (avoid assigning person to lParam every call)
- Is this for sharing?
It is to maintain state of the pointer
personbetween calls to the functionEditDlgProc().It ensures that:
Yes, Possibly. Difficult to say without knowing the design considerations.
No.
Note that the scope of an
staticvariable is limited to the function in this case, So it cannot be shared as such.