Platform SDK: DirectX

Synchronization

[C++]

An application can use two techniques to receive DirectPlay messages. The first is to check the receive queue during the main loop of the application. Typically, this means the application is single-threaded.

Alternatively, an application can have a separate thread to wait for messages and process them. In this case the application should supply a handle to a non-NULL, auto-reset synchronization event (see the Win32® CreateEvent function) when it creates players. DirectPlay will set this event when a message arrives for that player.

The message processing thread should then use the Win32 WaitForSingleObject function to wait until the event is set. Continue calling IDirectPlay4::Receive until it returns DPERR_NOMESSAGES, indicating that there are no more messages in the message queue.

If an application creates more than one local player, all can share the same event or each can have a separate event.

[Visual Basic]

An application can use two techniques to receive DirectPlay messages. The first is to check the receive queue during the main loop of the application. In Visual Basic, you might poll for messages in Sub Main, as in the following sample code:

Public Sub Main()
 
    Do While DoEvents()  ' Allow event processing
        ReceiveMessages  ' See Receiving Messages
    Loop
End Sub

Alternatively, the application can create an event that will be signaled whenever a player receives a message. In order to do so, you must implement the DirectXEvent class in a form or class module and supply a DirectXEvent.DXCallBack method. You then pass the DirectXEvent object (typically the form that implements the DirectXEvent class) to the DirectX7.CreateEvent method in order to get an event handle, and pass this handle to the DirectPlay4.CreatePlayer method in the receiveEvent parameter. Now, whenever a message is placed in the receive queue for that player, the DXCallBack method is automatically called, and within this procedure the application can retrieve any pending messages from the queue.

If an application creates more than one local player, all can share the same event or each can have a separate event.