Handling Lobby Launching

DirectPlay

 
Microsoft DirectX 9.0 SDK Update (Summer 2003)

Handling Lobby Launching


The first thing your lobbyable application should do when it is launched is to create and initialize a Microsoft® DirectPlay® lobbied application object. To do this, perform the following tasks.

  • Call CoCreateInstance to create a lobbied application object (CLSID_DirectPlay8LobbiedApplication). Set the riid parameter to IID_IDirectPlay8LobbiedApplication to request an IDirectPlay8LobbiedApplication interface.
  • Call IDirectPlay8LobbiedApplication::Initialize to initialize the lobbied application object. Pass the object a pointer to your lobbied application callback message handler.

Next, determine whether your application was lobby launched. If so, your application needs to set up a communication channel with DirectPlay so that you can effectively manage the session. Do the following to detect whether your application was lobby launched.

  • When the IDirectPlay8LobbiedApplication::Initialize method returns, examine the pdpnhConnection parameter. If this parameter is set to a valid connection handle, the game was lobby launched.
  • Examine the DPL_MSGID_CONNECT message you receive through your message handler. This message carries with it a variety of information, including the ID that you use to send messages to the lobby client.
Note  Your message handler may receive the DPL_MSGID_CONNECT message before the IDirectPlay8LobbiedApplication::Initialize method returns. Your message handler should be prepared to handle the message appropriately.

If your application was not lobby launched, you can indicate that your application is available to lobby clients for connection by calling IDirectPlay8LobbiedApplication::SetAppAvailable. This method is typically called when the application has been launched by the user. However, it can also be used if the user has closed one session but the application is still running and available for another session. In either case, your message handler receives a DPL_MSGID_CONNECT message when the lobby client connects your application to a session.

The following sample code illustrates how to initialize a lobbied application, and how to detect whether an application was lobby launched. It is a simplified version of the InitDirectPlay function used by the SimplePeer application in the software development kit (SDK). Refer to that sample application for the complete code. In particular, error-handling code has been deleted for clarity. The g_bWasLobbyLaunched variable is a global variable that is set to TRUE if the application was lobby launched.

HRESULT InitDirectPlay()
{
  DPNHANDLE hLobbyLaunchedConnection = NULL;
  HRESULT hr;

  // Create IDirectPlay8LobbiedApplication
  hr = CoCreateInstance( CLSID_DirectPlay8LobbiedApplication, NULL, 
                         CLSCTX_INPROC_SERVER,
                         IID_IDirectPlay8LobbiedApplication, 
                         (LPVOID*) &g_pLobbiedApp );

  // Initialize IDirectPlay8LobbiedApplication
  hr = g_pLobbiedApp->Initialize( NULL,
                                  DirectPlayLobbyMessageHandler, 
                                  &hLobbyLaunchedConnection,
                                  0 );
  //Check for a valid connection handle. If it is non-NULL
  //the application was lobby launched.
  g_bWasLobbyLaunched = ( hLobbyLaunchedConnection != NULL );

  return S_OK;
}

© 2003 Microsoft Corporation. All rights reserved.