Initiating a Peer-to-Peer Session

A peer-to-peer game can be launched directly by the user, or
lobby-launched by a
lobby client application that resides on the user's computer. This documentation will assume that the game is lobbyable, and can communicate with the lobby client.

One of the first steps you should take is to determine whether your game was lobby-launched. To do so, create and initialize a lobbied application object (CLSID_DirectPlay8LobbiedApplication). When you do so, you pass the object a pointer to your lobbied application message handler. This message handler receives messages directly from the lobbied application object, and indirectly from the lobby client and the lobby.

If the application was lobby-launched, the IDirectPlay8LobbiedApplication::Initialize method returns a connection handle to the lobby client and a DPL_MSGID_CONNECT message is sent to your lobbied application message handler. The pdplConnectionSettings member of the associated structure points to a DPL_CONNECTION_SETTINGS structure that contains connection information such as address objects for the members of the session.

If the application was not lobby launched, you will receive neither the connection handle, nor the message. However, if you call IDirectPlay8LobbiedApplication::SetAppAvailable, a lobby client can later connect your running application to a session by sending your lobbied application message handler a DPL_MSGID_CONNECT message.

You should also create and initialize a peer object (CLSID_DirectPlay8Peer). This object will be your primary means of communicating with Microsoft?DirectPlay? and the other users in the session. If you want to have multiple players in the session, you must create a separate instance of this object for each player.