DirectX SDK |
The IDirectPlay4::CreatePlayer method creates a local player for the current session.
HRESULT CreatePlayer( LPDPID lpidPlayer, LPDPNAME lpPlayerName, HANDLE hEvent, LPVOID lpData, DWORD dwDataSize, DWORD dwFlags );
Returns DP_OK if successful, or one of the following error values otherwise:
DPERR_CANTADDPLAYER |
DPERR_CANTCREATEPLAYER |
DPERR_CONNECTIONLOST |
DPERR_INVALIDFLAGS |
DPERR_INVALIDPARAMS |
DPERR_NOCONNECTION |
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 DPMSG_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 IDirectPlay4::DestroyPlayer, the session host or the application that created the player can destroy the player at any time.
If the application uses a separate thread to retrieve DirectPlay messages, it is highly recommended that a non-NULL hEvent be supplied and used for synchronization. This event will be set when this player receives a message. Within the message receive thread, use the Win32® API WaitForSingleObject (or use WaitForMultipleObjects if more than one event is used) within the thread to determine if a player has messages. It is inefficient to loop on IDirectPlay4::Receive inside a separate thread waiting for a message. The same event can be used for all the local players, or the application can supply different events for each player. The application is responsible for creating and destroying the event. See Synchronization for more information.
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
Header: Declared in dplay.h.
Import Library: Use dplayx.lib.
DPNAME, DPMSG_CREATEPLAYERORGROUP, IDirectPlay4::DestroyPlayer, IDirectPlay4::EnumPlayers, IDirectPlay4::Receive, IDirectPlay4::Send, IDirectPlay4::SetPlayerData, IDirectPlay4::SetPlayerName, IDirectPlay4::GetPlayerFlags