The message-management functions help your application route messages among players. With the exception of a small number of messages that the system has defined, the messages can be defined in any way the application requires. Your application can use the IDirectPlay2::Send method to send a message to a player, a group, or all the players in the session by specifying a player ID, a group ID, or DPID_ALLPLAYERS, respectively, as the destination. There is no limit to the size of the message that DirectPlay can send. Your application can call IDirectPlay2::GetCaps to find out the maximum number of bytes that can be sent in a single packet. Larger messages are sent by using several packets.
If the global state of a player or group changes and that change must be propagated to all the other players in the session, it might be more convenient to use the data management functions rather than send a message with the new data to the players. For more information, see Data Management.
To receive a message from the message queue, your application can use the IDirectPlay2::Receive method. This method allows your application to specify whether to receive the first message in the queue, only the messages to a particular player ID, or only those from a particular player ID. Your application can use the IDirectPlay2::GetMessageCount method to retrieve the number of messages waiting for a given player.
DirectPlay generates system messages that notify players of changes in the session. All system messages are from a virtual player defined by DPID_SYSMSG. System messages start with a 32-bit value that identifies the type of message. Constants that represent system messages begin with DPSYS_, and they have a corresponding message structure that must be used to interpret them. The application can control what system messages are generated by using flags in the DPSESSIONDESC2 structure.
If an application uses a separate thread for retrieving messages, the application can specify a synchronization event that will be set when a message is received.