Hi,
I have put the windows procedure inside a class as a static member function and I get a pointer to the class containing the function using GetWindowLong(), and everything works fine, like calling member functions trough the pointer and reading variables through the pointer, but when I try to write through the pointer, I get an Access violation writing location... Does anyone know why?
the code:
LRESULT CALLBACK Win32Window::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Get a pointer to the class which this window belongs to
Win32Window *w32Window;
if (msg != WM_CREATE)
w32Window = (Win32Window*)GetWindowLongPtr( hWnd, 0 );
switch (msg)
{
case WM_CREATE:
{
CREATESTRUCT *cs = (CREATESTRUCT*)lParam;
w32Window = (Win32Window*)cs->lpCreateParams;
SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR) w32Window);
return 0;
break;
}
case WM_KEYDOWN:
{
w32Window->aMemberVariable = 0; // this causes a Access violation writing...
break;
}
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}