Platform SDK: DirectX |
This tutorial pertains only to applications written in Visual Basic. See DirectPlay C/C++ Tutorials
On the frmSessions form of the Memory sample, the user has the choice of joining a listed session or creating a new one.
In both cases the procedure is the same: describe the session in a DirectPlaySessionData object, then pass this object to DirectPlay4.Open.
The following code, from the cmdCreate_Click method in frmCreateGame, creates a new game that will accept from two to four players, as specified by the choice of option buttons:
Dim SessionData As DirectPlaySessionData Set SessionData = gObjDPlay.CreateSessionData . . . ' Set number of players If Option1.Value = True Then Call SessionData.SetMaxPlayers(2) ElseIf Option2.Value = True Then Call SessionData.SetMaxPlayers(3) Else Call SessionData.SetMaxPlayers(4) End If ' Finish describing the session Call SessionData.SetSessionName(txtGameName.Text) Call SessionData.SetGuidApplication(AppGuid) Call SessionData.SetFlags(DPSESSION_MIGRATEHOST) ' Create (and join) the session. ' Failure can result from the user cancelling out of the service ' provider dialog. In the case of the modem, this is the "answer" ' dialog. On Error GoTo FAILEDOPEN Call gObjDPlay.Open(SessionData, DPOPEN_CREATE) . . . End Sub
Joining a session is a bit simpler, because the application just has to retrieve the session description from the enumeration, as in the cmdJoin_Click method of frmSessions:
Dim SessionData As DirectPlaySessionData Set SessionData = gObjDPEnumSessions.GetItem( _ lstSessions.ListIndex + 1) On Error GoTo NOSESSION Call gObjDPlay.Open(SessionData, DPOPEN_JOIN)
Next: Step 4: Create a Player