Microsoft DirectX 8.1 (Visual Basic)

DirectPlay8Peer.Connect

Establishes the connection to the server. After a connection is established, the communication channel on the object is open and active and the application should expect messages to arrive immediately. No messages can be sent by means of the DirectPlay8Peer.SendTo method until the connection has completed.

Before this method is called, it must obtain an application description by calling DirectPlay8Peer.EnumHosts. The EnumHosts method returns a DPN_APPLICATION_DESC type for each hosted application. The type describes the application, including the GUID of the application.

Although the application GUID is not required, Microsoft® DirectPlay® performs verification if one is specified.

When the connection to the host is requested, the DirectPlay8Event.IndicateConnect method is called in the host's message handler. The host may either accept or reject the connection. In either case, after the host has acted, the client message handler's DirectPlay8Event.ConnectComplete method will be called to convey the response.

Connect(AppDesc As DPN_APPLICATION_DESC, _
    Address As DirectPlay8Address, _
    DeviceInfo As DirectPlay8Address, _
    lFlags As Long, _
    UserData As Any, _
    UserDataSize As Long) As Long

Parts

AppDesc
DPN_APPLICATION_DESC type that describes the application. Only some of the members of this type are used by this method. The only member of this type that you must set is the guidApplication member. You can also set guidInstance, Password, and lFlags.
Address
Optional DirectPlay8Address object that specifies the addressing information to use to connect to the computer that is hosting.
DeviceInfo
DirectPlay8Address object that specifies what service provider to enumerate and what settings to use.
lFlags
Flag that describes the connection mode. You can set the following flag.
DPNOP_SYNC
Process the connection request synchronously. If this flag is set, DirectPlay will not call the DirectPlay8Event.ConnectComplete method.
UserData
Application-specific user data.
UserDataSize
Size of the data contained in the UserData parameter.

Return Values

Returns the asynchronous handle for this operation. This is the handle that is used in lAsyncHandle parameter of the DirectPlay8Peer.CancelAsyncOperation method to cancel the request, if the request is processed asynchronously.

Error Codes

If the method fails, Err.Number can be set to one of the following values.

DPNERR_NOCONNECTION
DPNERR_INVALIDPASSWORD
DPNERR_INVALIDFLAGS
DPNERR_INVALIDINTERFACE
DPNERR_INVALIDAPPLICATION
DPNERR_NOTHOST
DPNERR_SESSIONFULL
DPNERR_HOSTREJECTEDCONNECTION
DPNERR_INVALIDINSTANCE

Remarks

Although multiple enumerations can be run concurrently, and can be run across the duration of a connection, only one connection is allowed per object. To establish a connection to more than one application, you must create another object. That is, only one running application per object is allowed. If DirectPlay8Peer.Connect is called while another connection is in progress, the function raises an error.

After a call to DirectPlay8Peer.Connect succeeds, all outstanding enumerations are canceled with the DPNERR_USERCANCEL error value set.