I tried to build my Win32 API project for x64 with Visual Studio 2013. But the routed WindowProc Callback isn't working properly. I'm using SetWindowLongPtr/GetWindowLongPtr together with GWLP\_USERDATA to store an this pointer of my window. In the past I used SetWindowLong/GetWindowLong and GWL\_USERDATA for this purpose - but these are gone on x64. However on x86 everything still works fine (even with SetWindowLongPtr/GetWindowLongPtr and GWLP\_USERDATA), but on x64 there's an access violation as soon as I try to access any method/member inside my member function WindowProc.

```
#include <windows.h>
#include <stdio.h>
#include "main.h"

class Window{
public:
  Window(const char* title, const float width, const float height){
    char windowClass[255];
    sprintf_s(windowClass, "WindowClass%s", title);
    WNDCLASSEX wc;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc = WindowProcRouter;
    wc.hInstance = nullptr;
    wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = windowClass;
    RegisterClassEx(&wc);
    DWORD dwStyle = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
    RECT WindowRect;
    WindowRect.left = (long)0;
    WindowRect.right = (long)width;
    WindowRect.top = (long)0;
    WindowRect.bottom = (long)height;
    AdjustWindowRect(&WindowRect, dwStyle, FALSE);
    hWnd = CreateWindowEx(0,
      windowClass,
      title,
      dwStyle,
      0, 0,
      WindowRect.right - WindowRect.left,
      WindowRect.bottom - WindowRect.top,
      nullptr,
      nullptr,
      wc.hInstance,
      (LPVOID) this);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    ShowWindow(hWnd, SW_SHOW);
    SetFocus(hWnd);
    closed = false;
  }

  static LRESULT CALLBACK Window::WindowProcRouter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
    LRESULT returnValue = 0;
    Window* pWnd = nullptr;
    if (uMsg == WM_NCCREATE){
      SetWindowLongPtr(hWnd, GWLP_USERDATA,
        (long)((LPCREATESTRUCT(lParam))->lpCreateParams));
    }
    pWnd = (Window*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
    if (pWnd){
      returnValue = pWnd->WindowProc(hWnd, uMsg, wParam, lParam);
    }
    else{
      returnValue = DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    return returnValue;
  }

  LRESULT CALLBACK Window::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
    switch (uMsg){
    case WM_DESTROY:
      closed = true;
      PostQuitMessage(0);
      break;
    default:
      break;
    }
    return DefWindowProc(hWnd, uMsg, wParam, lParam);
  }

  bool Window::isClosed(){
    return closed;
  }

  Window::~Window(){
    if (hWnd && !DestroyWindow(hWnd)){
      hWnd = nullptr;
    }
  }
private:
  HWND hWnd;
  bool closed;
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
  Window win("Title", 640, 480);
  MSG msg;
  while(!win.isClosed()){
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
  }
}

```

On the line `closed = true;` in `WindowProc` happens the violation.
Any ideas why?