I have two classes, both inherited from the same base class. It's for a game loop and depending on which "state" you're in, it should send a pointer to the active object in the CALLBACK method - but it doesn't. It only sends the second object's pointer.
If I set ObjectA first through PostMessage() and ObjectB secondly ObjectB doesn't work, it doesn't get a pointer to that object.
And if I set the opposite, ObjectB works while ObjectA doesn't.
This is the general layout of the loop: (what am I missing?)
Game loop:
PostMessage( hwnd, WM_USER, 0, (LPARAM)&ObjectA );
PostMessage( hwnd, WM_USER, 0, (LPARAM)&ObjectB );
while(running)
{
while( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
{
/* ... */
}
if (STATE == StateA)
Update(&ObjectA);
if (STATE == StateB)
Update(&ObjectB);
}
In Callback method:
static ObjectA* objA;
static ObjectB* objB;
if (objA || objB)
{
// Do stuff to objA or objB
}
else
switch(msg)
{
case WM_USER:
if (STATE == StateA)
objA = (ObjectA*) lparam;
if (STATE == StateB)
objB = (ObjectB*) lparam;
break;
// default and WM_CLOSE
}
}