Platform SDK: DirectX |
A modem-to-modem service provider uses Telephony API (TAPI) to communicate with another modem. The service provider supports only nonguaranteed messaging. You can use the DirectPlay protocol for guaranteed messaging for modem sessions.
Creating a session causes a dialog box to appear, asking the user for a modem selection and configuration, and then letting the user put the modem in autoanswer mode. Enumerating sessions will also trigger a dialog box asking the user what phone number to call and which modem to use. After the information is entered, DirectPlay will dial the modem and try to find sessions hosted by the computer on the other end.
To enumerate the modem sessions without any dialog boxes (when, for example, the phone number is known by the application and was given to the service provider when IDirectPlay4::InitializeConnection was called), use IDirectPlay4::EnumSessions in a loop with the DPENUMSESSIONS_RETURNSTATUS flag (see EnumSessions for more details). When DP_OK is returned, the application should then use EnumSessions one more time to obtain the actual list of sessions.
When using EnumSessions in a loop like this, the application must implement a windows message loop as follows:
while (lpDPLAY->EnumSessions(lpsd, 0, lpEnumSessionsCallback, lpContext, DPENUMSESSIONS_RETURNSTATUS) == DPERR_CONNECTING) { MSG msg; if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } Sleep(500); }
If you insert too many delays into the message processing, you can lose packets—for example, if you print a lot of debug information.
The current list of available modems can be obtained from the service provider by initializing it and calling the IDirectPlay4::GetPlayerAddress method with a player ID of zero. The DirectPlay address returned will contain a data chunk with the ANSI modem names (DPAID_Modem) and the Unicode modem names (DPAID_ModemW). The list of modems is a series of null-terminated strings with a zero-length string at the end of the list. For more information, see DirectPlay Address Data Types.
To enumerate the modem sessions without any dialog boxes (when, for example, the phone number is known by the application and was given to the service provider when DirectPlay4.InitializeConnection was called), call DirectPlay4.GetDPEnumSessions repeatedly with the DPENUMSESSIONS_RETURNSTATUS flag until it does not raise the DPERR_CONNECTING error. You should allow events to be processed while executing the loop. The following sample code illustrates one way to do this:
' objDPlay is the DirectPlay4 object ' SessionData is a DirectPlaySessionData object containg valid info. On Error GoTo DO_AGAIN Do While DoEvents objDPlay.GetDPEnumSessions(SessionData, 0, _ DPENUMSESSIONS_AVAILABLE Or DPENUMSESSIONS_RETURNSTATUS) Exit Do ' No error, enumeration complete DO_AGAIN: ' If some other error, give up if Err.Number <> DPERR_CONNECTING Then ' Handle error – can't enumerate sessions Exit Do End If ' Still connecting, so try again Loop On Error GoTo 0
The names available modems can be obtained from the service provider by initializing it and calling the DirectPlayLobby3.GetModemName method for index values from 1 to the value returned by DirectPlayLobby3.GetModemCount.
The modem-to-modem service provider GUID can be specified as DPSPGUID_MODEM.