1 | //Look for a Hello World Session which might be already running |
2 | static HRESULT FindSession() |
3 | { |
4 | HRESULT hr; |
5 | DPSESSIONDESC sessionDesc; |
6 | ZeroMemory(&sessionDesc, sizeof(DPSESSIONDESC)); |
7 | sessionDesc.dwSize = sizeof(DPSESSIONDESC); |
8 | sessionDesc.guidSession = sessionGUID; |
9 | hr = lpDirectPlay1->EnumSessions(&sessionDesc, 1000, EnumSessionsCallback, |
10 | hwndApp, DPENUMSESSIONS_AVAILABLE); |
11 | if FAILED(hr) |
12 | ::MessageBox(NULL,"Could not find any HelloWorld sessions", "HelloWorld", MB_OK); |
13 | return(hr); |
14 | } |
15 | // Callback function for enumerating sessions |
16 | static BOOL FAR PASCAL EnumSessionsCallback( |
17 | LPDPSESSIONDESC lpSessionDesc, |
18 | LPVOID lpContext, |
19 | LPDWORD lpdwTimeOut, |
20 | DWORD dwFlags |
21 | ) |
22 | { |
23 | if (dwFlags & DPESC_TIMEDOUT) |
24 | ::MessageBox(NULL,"Could not find a HelloWorld session!....Timed Out", "HelloWorld", MB_OK); |
25 | else |
26 | ::MessageBox(NULL,"Found a HelloWorld session!", "HelloWorld", MB_OK); |
27 | return(FALSE); |
28 | } |
29 | FindSession(): |
30 | Enumerates other DirectPlay |
31 | sessions with same GUID |
32 | EnumSessionsCallback() |
33 | is called by DirectPlay for each session it finds. |