Microsoft DirectX 9.0

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.

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.

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;

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

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

  return S_OK;

© 2002 Microsoft Corporation. All rights reserved.