A Sample Lobbied Application Message Handler
The following code is a simplified version of the message handler from the SimplePeer 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_CONNECT:
{
PDPL_MESSAGE_CONNECT pConnectMsg;
pConnectMsg = (PDPL_MESSAGE_CONNECT)pMsgBuffer;
// Connected. Start the session.
break;
}
case DPL_MSGID_DISCONNECT:
{
PDPL_MESSAGE_DISCONNECT pDisconnectMsg;
pDisconnectMsg = (PDPL_MESSAGE_DISCONNECT)pMsgBuffer;
// Disconnected. Free any data associated with
// the lobby client.
break;
}
case DPL_MSGID_RECEIVE:
{
PDPL_MESSAGE_RECEIVE pReceiveMsg;
pReceiveMsg = (PDPL_MESSAGE_RECEIVE)pMsgBuffer;
// The lobby client sent data. Process the data and
// respond appropriately.
break;
}
case DPL_MSGID_CONNECTION_SETTINGS:
{
PDPL_MESSAGE_CONNECTION_SETTINGS pConnectionStatusMsg;
pConnectionStatusMsg = (PDPL_MESSAGE_CONNECTION_SETTINGS)pMsgBuffer;
// The lobby client has changed the connection settings.
break;
}
}
return S_OK;
}