I create a window class with static window proc for dialog window and have an error executed when window is creating: access denied when writing location "0x00000000"
// ... Creating window
_hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, WndProc, (LPARAM)this);
And window proc function:
static INT_PTR CALLBACK MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
MainWindow * wnd = NULL;
if(message == WM_NCCREATE) {
wnd = reinterpret_cast<MainWindow *>(((LPCREATESTRUCT)lParam)->lpCreateParams);
::SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<long>(wnd));
wnd->_hWnd = hWnd;
} else
wnd = reinterpret_cast<MainWindow *>(::GetWindowLongPtr(hWnd, GWLP_USERDATA));
// ...
}
A dialog's "first message" is
WM_INITDIALOG
rather thanWM_NCCREATE
. The user data param is passed directly as thelParam
value (rather than via aLPCREATESTRUCT
pointed to bylParam
).