Microsoft DirectX 9.0 SDK Update (Summer 2003) |
The following code is a simplified version of the message handler from the LobbyClient sample in the software development kit (SDK). Error handling code has been removed for clarity. See the sample for a complete version.
HRESULT WINAPI DirectPlayLobbyMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer ) { switch( dwMessageId ) { case DPL_MSGID_DISCONNECT: { PDPL_MESSAGE_DISCONNECT pDisconnectMsg; pDisconnectMsg = (PDPL_MESSAGE_DISCONNECT)pMsgBuffer; // Free any data associated with the application and // remove the connection from the list. break; } case DPL_MSGID_RECEIVE: { PDPL_MESSAGE_RECEIVE pReceiveMsg; pReceiveMsg = (PDPL_MESSAGE_RECEIVE)pMsgBuffer; // The lobby application sent data. Process the data and // respond appropriately. break; } case DPL_MSGID_SESSION_STATUS: { PDPL_MESSAGE_SESSION_STATUS pStatusMsg; pStatusMsg = (PDPL_MESSAGE_SESSION_STATUS)pMsgBuffer; switch( pStatusMsg->dwStatus ) { case DPLSESSION_CONNECTED: // Session connected. break; case DPLSESSION_COULDNOTCONNECT: // Session could not connect. break; case DPLSESSION_DISCONNECTED: // Session disconnected. break; case DPLSESSION_TERMINATED: // Session terminated. break; case DPLSESSION_HOSTMIGRATED: // Host migrated. break; case DPLSESSION_HOSTMIGRATEDHERE: // Host migrated here. break; } case DPL_MSGID_CONNECTION_SETTINGS: { PDPL_MESSAGE_CONNECTION_SETTINGS pConnectionStatusMsg; pConnectionStatusMsg = (PDPL_MESSAGE_CONNECTION_SETTINGS)pMsgBuffer; // The application has changed the connection settings. break; } } return S_OK; }