Microsoft DirectX 9.0


AddressOverride demonstrates how to programmatically provide an address to Microsoft?DirectPlay?in order to host or connect to another session on the network. The alternative is to have DirectPlay display a standard dialog box to ask the user the connection settings. Most games will set addresses directly so that they can provide their own user interface.


Source: (SDK root)\Samples\C++\DirectPlay\AddressOverride

Executable: (SDK root)\Samples\C++\DirectPlay\Bin

User's Guide

The AddressOverride sample displays a dialog box that allows you to select address parameters. To use the dialog box:

  1. Enter the player's name and session.
  2. If you want to be a session host, select the Host Session check box.
  3. Choose a service provider from the Service Provider list.
  4. Choose an adapter from the Adapter list.
  5. The remaining steps depend on which service provider you choose.
    • If you choose the Transmission Control Protocol/Internet Protocol (TCP/IP) service provider:
      • To join a session, select a particular host by entering its Internet Protocol (IP) address and port in the associated edit boxes. You can also have DirectPlay search the local network for available hosts by leaving the IP address and Port boxes blank.
      • To host a session, you can specify a port. If you leave the Port box blank, DirectPlay will select a port for you.
    • If you choose the model service provider, enter the phone number.
    • If you choose the Internetwork Packet Exchange (IPX) service provider, enter the port.
    • If you choose the serial service provider, the sample will launch the default DirectPlay dialog box that queries the user for serial settings.

Once you have finished filling in the Address Override dialog box, click OK to start or join a game. This game is similar to SimplePeer. See the SimplePeer user's guide for more details.

Programming Notes

The AddressOverride sample is very similar to the SimplePeer sample. See the Programming Notes section of the SimplePeer sample for details. AddressOverride differs by programmatically specifying an address, rather than having DirectPlay display the default address selection dialog box.

The following list outlines how the AddressOverride sample works. When the OK button is pressed, the sample:

  1. Determines whether the user wants to host or join a session from the Host Session check box.
  2. Determines the service provider from the Service Provider list, and selects the appropriate globally unique identifier (GUID).
  3. Creates an IDirectPlay8Address object called pDeviceAddress.
  4. Calls that object's IDirectPlay8Address::SetSP method to specify the service provider.
  5. If the user is hosting a session, creates an IDirectPlay8Address object called pHostAddress. It then calls that object's IDirectPlay8Address::SetSP method to specify the service provider.
  6. If an adapter was specified, the sample calls the pDeviceAddress object's IDirectPlay8Address::SetDevice to specify the adapter.

The sample then calls IDirectPlay8Address::AddComponent to complete the initialization of the address objects. The details depend on which service provider was selected, and whether the user is joining or hosting a session.

Use the device and host address objects to connect to the session, much like the SimplePeer sample.

© 2002 Microsoft Corporation. All rights reserved.