Code: Select all
gSmartFox = new Sfs2X::SmartFox(true);
gSmartFox->ThreadSafeMode(true);
// Add event listeners
pConnectionTest = new ConnectionTest(gSmartFox);
gSmartFox->AddEventListener(SFSEvent::CONNECTION, new EventListenerDelegate(ConnectionTest::OnSmartFoxConnection, (void*)pConnectionTest));
gSmartFox->AddEventListener(SFSEvent::CONNECTION_LOST, new EventListenerDelegate(ConnectionTest::OnSmartFoxConnectionLost, (void*)pConnectionTest));
gSmartFox->AddEventListener(SFSEvent::LOGIN, new EventListenerDelegate(ConnectionTest::OnSmartFoxLogin, (void*)pConnectionTest));
......
while (GetMessage(&msg, NULL, 0, 0))
{
gSmartFox->ProcessEvents();
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
turn ThreadSafeMode on and call gSmartFox->ProcessEvents(), i get OnSmartFoxConnection when connect, and OnSmartFoxLogin after send login request.
if i don't call gSmartFox->ProcessEvents():
Code: Select all
while (GetMessage(&msg, NULL, 0, 0))
{
//gSmartFox->ProcessEvents();
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
i don't get OnSmartFoxConnection at first, but after send login request, i can still get OnSmartFoxLogin callback.