Microsoft DirectX 9.0 SDK Update (Summer 2003) |
Initializing a Lobby Client
Lobby clients are launched either by a lobby server or directly, by a user. When a lobby client is launched, it must be initialized before it can launch an application. Initialization involves the following tasks.
- Call CoCreateInstance to create a lobby client object (CLSID_DirectPlay8LobbyClient). Use the riid parameter to request an IDirectPlay8LobbyClient interface (IID_IDirectPlay8LobbyClient).
- Call the lobby client's IDirectPlay8LobbyClient::Initialize method. Pass the method a pointer to your lobby client's callback message handler.
- Use the IDirectPlay8LobbyClient::EnumLocalPrograms method to enumerate the lobbyable applications on the user's system.
The first two steps create the lobby client object, and set up a communication link between that object and your lobby client. The final step determines what lobbyable applications are available on the user's system. You need this information in order to launch the selected application.
The following code sample illustrates how to enumerate local applications. It is a simplified version of the EnumRegisteredApplications function in the LobbyClient sample found in the software development kit (SDK). Code related to error handling and to the dialog box has been deleted for clarity. See the LobbyClient sample in the SDK for the complete code.
HRESULT EnumRegisteredApplications() { HRESULT hr; DWORD dwSize = 0; DWORD dwPrograms = 0; DWORD iProgram; BYTE* pData = NULL; // g_pLobbyClient is a pointer to an IDirectPlay8LobbyClient interface // Start with a NULL data buffer. The required buffer size is // returned through dwSize. hr = g_pLobbyClient->EnumLocalPrograms( NULL, pData, &dwSize, &dwPrograms, 0 ); if( dwSize == 0 ) { // No registered applications. } // Set the data buffer to the appropriate size pData = new BYTE[dwSize]; hr = g_pLobbyClient->EnumLocalPrograms( NULL, pData, &dwSize, &dwPrograms, 0 ) // Cast the returned data to the appropriate structure type DPL_APPLICATION_INFO* pAppInfo = (DPL_APPLICATION_INFO*) pData; // Enumerate the names of the registered applications for( iProgram=0; iProgram<dwPrograms; iProgram++ ) { TCHAR strAppName[MAX_PATH]; DXUtil_ConvertWideStringToGeneric( strAppName, pAppInfo->pwszApplicationName, MAX_PATH ); } SAFE_DELETE_ARRAY( pData ); return S_OK; }