DirectX SDK

DirectPlay4.CreatePlayer

The DirectPlay4.CreatePlayer method creates a local player for the current session.

object.CreatePlayer(friendlyName As String, _
    formalName As String, _
    receiveEvent As Long, _
    flags As CONST_DPPLAYERFLAGS) As Long

Parameters

object
Object expression that resolves to a DirectPlay4 object.
friendlyName
Handle that can be used to identify and access the created player. This token identifier should differ from formalName.
formalName
Handle that can be used to identify and access the created player. This token identifier should differ from friendlyName.
receiveEvent
Handle for an event created by the application that DirectPlay will signal when a message addressed to this player is received.
flags
Flags indicating what type of player this is. Default (flags = 0) is a nonspectator, nonserver player.
DPPLAYER_SERVERPLAYER
The player is a server player for client/server communications. Only the host can create a server player. There can be only one server player in a session. CreatePlayer will always return a player ID of DPID_SERVERPLAYER if this flag is specified.
DPPLAYER_SPECTATOR
The player is created as a spectator. The behavior of a spectator player is completely defined by the application. DirectPlay simply propagates this flag.

Return Values

If it succeeds, the method returns a unique player ID.

Error Codes

If the method fails, an error is raised and Err.Number may be set to one of the following values:

DPERR_CANTADDPLAYER
DPERR_CANTCREATEPLAYER
DPERR_CONNECTIONLOST
DPERR_INVALIDFLAGS
DPERR_INVALIDPARAMS
DPERR_NOCONNECTION

Remarks

A single process can have multiple local players that communicate through a DirectPlay object with other players on the same computer or players on remote computers.

Upon successful completion, this method sends a DPSYS_CREATEPLAYERORGROUP system message to all the other players in the session announcing that a new player has joined the session. By default, all local players receive copies of all the system messages.

Your application should use the player ID returned to the application to identify the player for message passing and data association. Player and group IDs assigned by DirectPlay will always be unique within the session.

Only the application that created the player can:

If the application closes the session, any local players created will be automatically destroyed. Using the DirectPlay4.DestroyPlayer method, the session host or the application that created the player can destroy the player at any time.

See Also

DirectPlay4.GetDPEnumPlayers, DirectPlay4.GetPlayerFlags, DirectPlay4.Send, DirectPlay4.SetPlayerData, DirectPlay4.SetPlayerName, DirectX7.CreateEvent