Platform SDK: DirectX |
At this point the two code branches—lobby launch and user launch—converge. The program has retrieved the connection settings from the lobby and can proceed to connect the application session to a local DirectPlay4 object, represented here by objDPlay:
GOTCONNECTION: On Local Error GoTo FAILED Set objDPlay = objDPLobby.Connect(0)
Now the application can get whatever information it needs about the session and can create a player based on the information in the connection data:
' The following were declared globally: ' Dim objDPSessionData as DirectPlaySessionData ' Dim gMyPlayerName As String ' Dim gMyPlayerID As Long Set objDPSessionData = objDPLConnection.GetSessionDesc ' The session data includes the name of the session, number ' of players, and so on, all of which was set in the staging area. gMyPlayerName = objDPLConnection.GetPlayerShortName gMyPlayerID = objDPlay.CreatePlayer(gMyPlayerName, "PLAYER", _ 0, DPPLAYER_DEFAULT) Exit Function
Now everything is in place for the player to begin sending and receiving messages.
If anything has gone awry, the error handler sets the return value of InitDPlay to False and the application can exit gracefully:
FAILED: InitDPlay = False End Function