One drawback of external lobby launching is that the lobby server always tells the lobby client to launch a new instance of the application, even if one is already running. You can avoid a redundant launch by supporting dynamic lobby connection.
The instructions in this section assume the application is already running and has a connection to a lobby server that will return connection settings.
[C++]
At startup, create an IDirectPlayLobby3 interface by using the CoCreateInstance function.
Allow the user to select "Wait for lobby connection", or words to that effect, rather than making a manual connection. Take the following steps only if that selection has been made. (See the Duel sample for one implementation.)
Call IDirectPlayLobby3::WaitForConnectionSettings to put your application in wait mode. This does not block execution, it simply tells DirectPlay that the application is active and waiting for a connection, so that the lobby client's call to DirectPlayLobby3::RunApplication will not launch another instance.
Wait for a lobby message to come in by using IDirectPlayLobby3::ReceiveLobbyMessage. The message type to expect is the DPLSYS_NEWCONNECTIONSETTINGS system message. Note that you can call WaitForConnectionSettings again to cancel wait mode in response to a user cancel.
Call IDirectPlayLobby3::ConnectEx to create or join the application session. (The application knows whether it is to create or join a session by examining DPLCONNECTION.dwFlags.)
Create a player using the name information supplied in the DPLCONNECTION structure obtained in step 5.
Allow the user to select "Wait for lobby connection", or words to that effect, rather than making a manual connection. Take the following steps only if that selection has been made.
Call DirectPlayLobby3.WaitForConnectionSettings to put your application in wait mode. This does not block execution, it simply tells DirectPlay that the application is active and waiting for a connection, so that the lobby client's call to DirectPlayLobby3.RunApplication will not launch another instance.
Wait for a lobby message to come in by using DirectPlayLobby3.ReceiveLobbyMessage. The message type to expect is the DPLSYS_NEWCONNECTIONSETTINGS system message. Note that you can call WaitForConnectionSettings again to cancel wait mode in response to a user cancel.