//Look for a Hello World Session which might be already running |
static HRESULT FindSession() |
{ |
HRESULT hr; |
DPSESSIONDESC sessionDesc; |
ZeroMemory(&sessionDesc, sizeof(DPSESSIONDESC)); |
sessionDesc.dwSize = sizeof(DPSESSIONDESC); |
sessionDesc.guidSession = sessionGUID; |
hr = lpDirectPlay1->EnumSessions(&sessionDesc, 1000, EnumSessionsCallback, |
hwndApp, DPENUMSESSIONS_AVAILABLE); |
if FAILED(hr) |
::MessageBox(NULL,"Could not find any HelloWorld sessions", "HelloWorld", MB_OK); |
return(hr); |
} |
// Callback function for enumerating sessions |
static BOOL FAR PASCAL EnumSessionsCallback( |
LPDPSESSIONDESC lpSessionDesc, |
LPVOID lpContext, |
LPDWORD lpdwTimeOut, |
DWORD dwFlags |
) |
{ |
if (dwFlags & DPESC_TIMEDOUT) |
::MessageBox(NULL,"Could not find a HelloWorld session!....Timed Out", "HelloWorld", MB_OK); |
else |
::MessageBox(NULL,"Found a HelloWorld session!", "HelloWorld", MB_OK); |
return(FALSE); |
} |
FindSession(): |
Enumerates other DirectPlay |
sessions with same GUID |
EnumSessionsCallback() |
is called by DirectPlay for each session it finds. |