I created win32 wrapper before but I lost the files… So I’m gonna creating them again. The problem is with my router(static window processor).
Here is my code
CFramework *wnd = 0;
// retrieve associated Window instance
wnd = reinterpret_cast<CFramework *>(::GetWindowLongPtr(hWnd, GWL_USERDATA));
// call the windows message handler
wnd->WndProc(hWnd, msg, wParam, lParam);
return true;
When I call GetWindowLongPtr it won’t retrieves the user data.
UPDATE:
I also tired this code that uses SetWindowLongPtr
if ( msg == WM_CREATE )
{
SetWindowLongPtr( hWnd, GWLP_USERDATA, (LONG)((CREATESTRUCT *)lParam)->lpCreateParams );
}
Window *targetApp = (Window*)GetWindowLongPtr( hWnd, GWLP_USERDATA );
if ( targetApp )
{
return targetApp->WndProc( hWnd, msg, wParam, lParam );
}
return DefWindowProc( hWnd, msg, wParam, lParam );
I used my second code.^^^^
I put break point at SetWindow…
It seems it never Get called!
Your window may receive some messages before
WM_CREATE. I did something like this a while ago, and there were sizing and positioning messages, along withWM_NCCREATE, that arrived before theWM_CREATE. So you shouldn’t expect to see the value there on those messages.Are you compiling for 32-bit or 64-bit? If 64-bit, then the cast to
LONGmay be whacking your pointer.And, as Rup said in the comments, you have to be really certain that nobody else is using
WM_USERDATA.