DirectX SDK

Tutorial 4: Create Self-Refreshing Session Lists

[Visual Basic]

This tutorial pertains only to applications written in C++. See DirectPlay Visual Basic Tutorials.

[C++]

An application can maintain a self-refreshing session list by calling IDirectPlay4::EnumSessions asynchronously. This technique is used in five of the DirectPlay samples: Bellhop, DPChat, DPSlots, Duel, and Override. You can find a code example in any of these sample applications.

The steps you need to follow to create a self-refreshing session list are as follows:

  1. Call IDirectPlay4::EnumSessions with the DPENUMSESSIONS_ASYNC flag and a time-out of zero (which will use the service provider default). The method will not enumerate any sessions and will return immediately. However, DirectPlay is enumerating sessions in the background.
  2. Display the user interface in which all the sessions will appear. Set a timer to go off at whatever interval you want to refresh your session list. The application can find out what the default time-out interval of the enumeration is by calling IDirectPlay4::GetCaps.
  3. Each time the timer goes off, call EnumSessions to obtain the current session list. This is a complete active session list with stale sessions deleted, new sessions added, and existing sessions updated. Delete all the items from the list before calling EnumSessions and add the sessions back to the list in the EnumSessionsCallback2 function.
  4. Check the error result returned by EnumSessions and stop the timer if an error other than DPERR_CONNECTING is returned. It is possible for the connection to be lost or canceled by the user.