Question

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));

    // ...
}
Was it helpful?

Solution

A dialog's "first message" is WM_INITDIALOG rather than WM_NCCREATE. The user data param is passed directly as the lParam value (rather than via a LPCREATESTRUCT pointed to by lParam).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top