Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

761 lines
22 KiB

  1. #include "stdafx.h"
  2. #include "Direct.h"
  3. #include "dms.h"
  4. #include "DPlayLobbyClientObj.h"
  5. #include "DplayAddressObj.h"
  6. extern HRESULT DPLAYBSTRtoGUID(LPGUID,BSTR);
  7. extern void *g_dxj_DirectPlayLobbyClient;
  8. extern void *g_dxj_DirectPlayAddress;
  9. extern BSTR GUIDtoBSTR(LPGUID);
  10. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  11. extern BOOL IsEmptyString(BSTR szString);
  12. #define SAFE_DELETE(p) { if(p) { delete (p); p=NULL; } }
  13. #define SAFE_RELEASE(p) { __try { if(p) { (p)->Release(); (p)=NULL;} } __except(EXCEPTION_EXECUTE_HANDLER) { (p) = NULL;} }
  14. DWORD WINAPI CloseLobbyClientThreadProc(void* lpParam);
  15. ///////////////////////////////////////////////////////////////////
  16. // InternalAddRef
  17. ///////////////////////////////////////////////////////////////////
  18. DWORD C_dxj_DirectPlayLobbyClientObject::InternalAddRef(){
  19. DWORD i;
  20. i=CComObjectRoot::InternalAddRef();
  21. DPF1(1,"------ DXVB: DirectPlayLobbyClient8 AddRef %d \n",i);
  22. return i;
  23. }
  24. ///////////////////////////////////////////////////////////////////
  25. // InternalRelease
  26. ///////////////////////////////////////////////////////////////////
  27. DWORD C_dxj_DirectPlayLobbyClientObject::InternalRelease(){
  28. DWORD i;
  29. i=CComObjectRoot::InternalRelease();
  30. DPF1(1,"------ DXVB: DirectPlayLobbyClient8 Release %d \n",i);
  31. return i;
  32. }
  33. ///////////////////////////////////////////////////////////////////
  34. // C_dxj_DirectPlayLobbyClientObject
  35. ///////////////////////////////////////////////////////////////////
  36. C_dxj_DirectPlayLobbyClientObject::C_dxj_DirectPlayLobbyClientObject(){
  37. DPF(1,"------ DXVB: Constructor Creation DirectPlayLobbyClient8 Object \n ");
  38. m__dxj_DirectPlayLobbyClient = NULL;
  39. m_ProgInfo = NULL;
  40. m_dwAppCount = 0;
  41. m_fInit = FALSE;
  42. m_pUserData = NULL;
  43. m_dwUserDataSize = 0;
  44. m_fHandleEvents = FALSE;
  45. m_pEventStream=NULL;
  46. }
  47. ///////////////////////////////////////////////////////////////////
  48. // ~C_dxj_DirectPlayLobbyClientObject
  49. ///////////////////////////////////////////////////////////////////
  50. C_dxj_DirectPlayLobbyClientObject::~C_dxj_DirectPlayLobbyClientObject()
  51. {
  52. DPF(1,"------ DXVB: Entering ~C_dxj_DirectPlayLobbyClientObject destructor \n");
  53. SAFE_RELEASE(m__dxj_DirectPlayLobbyClient);
  54. SAFE_DELETE(m_ProgInfo)
  55. m_fHandleEvents = FALSE;
  56. if (m_pEventStream)
  57. m_pEventStream->Release();
  58. }
  59. HRESULT C_dxj_DirectPlayLobbyClientObject::InternalGetObject(IUnknown **pUnk){
  60. *pUnk=(IUnknown*)m__dxj_DirectPlayLobbyClient;
  61. return S_OK;
  62. }
  63. HRESULT C_dxj_DirectPlayLobbyClientObject::InternalSetObject(IUnknown *pUnk){
  64. m__dxj_DirectPlayLobbyClient=(IDirectPlay8LobbyClient*)pUnk;
  65. return S_OK;
  66. }
  67. HRESULT WINAPI DirectPlayLobbyClientMessageHandler( PVOID pvUserContext,
  68. DWORD dwMessageId,
  69. PVOID pMsgBuffer )
  70. {
  71. HRESULT hr=S_OK;
  72. BOOL fCallCoUninit = FALSE;
  73. VARIANT_BOOL fRejectMsg = VARIANT_FALSE;
  74. // User context for the message handler is a pointer to our class module.
  75. C_dxj_DirectPlayLobbyClientObject *lpPeer = (C_dxj_DirectPlayLobbyClientObject*)pvUserContext;
  76. DPF(1,"-----Entering (DPlayLobbyClient) MessageHandler call...\n");
  77. if (!lpPeer) return E_FAIL;
  78. if (!lpPeer->m_pEventStream) return E_FAIL;
  79. if (!lpPeer->m_fHandleEvents)
  80. return S_OK;
  81. // First we need to set our stream seek back to the beginning
  82. // We will do this every time we enter this function since we don't know if
  83. // we are on the same thread or not...
  84. I_dxj_DirectPlayLobbyEvent *lpEvent = NULL;
  85. __try {
  86. LARGE_INTEGER l;
  87. l.QuadPart = 0;
  88. lpPeer->m_pEventStream->Seek(l, STREAM_SEEK_SET, NULL);
  89. hr = CoUnmarshalInterface(lpPeer->m_pEventStream, IID_I_dxj_DirectPlayEvent, (void**)&lpEvent);
  90. if (hr == CO_E_NOTINITIALIZED) // Call CoInit so we can unmarshal
  91. {
  92. CoInitialize(NULL);
  93. hr = CoUnmarshalInterface(lpPeer->m_pEventStream, IID_I_dxj_DirectPlayEvent, (void**)&lpEvent);
  94. fCallCoUninit = TRUE;
  95. }
  96. if (!lpEvent)
  97. {
  98. DPF(1,"-----Leaving (DplayLobbyClient) MessageHandler call (No event interface)...\n");
  99. return hr;
  100. }
  101. }
  102. __except(EXCEPTION_EXECUTE_HANDLER)
  103. {
  104. lpPeer->m_fHandleEvents = FALSE;
  105. DPF(1,"-----Leaving (DplayLobbyClient) MessageHandler call (Stream Gone)...\n");
  106. return S_OK;
  107. }
  108. switch( dwMessageId )
  109. {
  110. //Receive
  111. case DPL_MSGID_RECEIVE:
  112. {
  113. DPL_MESSAGE_RECEIVE *msg = (DPL_MESSAGE_RECEIVE*)pMsgBuffer;
  114. SAFEARRAY *lpData = NULL;
  115. SAFEARRAYBOUND rgsabound[1];
  116. DPL_MESSAGE_RECEIVE_CDESC m_dpReceive;
  117. BYTE *lpTemp = NULL;
  118. ZeroMemory(&m_dpReceive, sizeof(DPL_MESSAGE_RECEIVE));
  119. m_dpReceive.Sender = (long)msg->hSender;
  120. // Let's load our SafeArray
  121. if (msg->dwBufferSize)
  122. {
  123. rgsabound[0].lLbound = 0;
  124. rgsabound[0].cElements = msg->dwBufferSize;
  125. lpData = SafeArrayCreate(VT_UI1, 1, rgsabound);
  126. lpTemp = (BYTE*)lpData->pvData;
  127. lpData->pvData = msg->pBuffer;
  128. m_dpReceive.lBufferSize = msg->dwBufferSize;
  129. m_dpReceive.Buffer = lpData;
  130. }
  131. lpEvent->Receive(&m_dpReceive, &fRejectMsg);
  132. if (lpData) //Get rid of the safearray
  133. {
  134. lpData->pvData = lpTemp;
  135. SafeArrayDestroy(lpData);
  136. }
  137. break;
  138. }
  139. //Connect
  140. case DPL_MSGID_CONNECT:
  141. {
  142. DPL_MESSAGE_CONNECT *msg = (DPL_MESSAGE_CONNECT*)pMsgBuffer;
  143. DPNHANDLE m_hConnectID;
  144. DPL_MESSAGE_CONNECT_CDESC m_dpConnection;
  145. SAFEARRAY *lpData = NULL;
  146. SAFEARRAYBOUND rgsabound[1];
  147. WCHAR wszAddress[MAX_PATH];
  148. WCHAR wszDevice[MAX_PATH];
  149. DWORD dwNumChars = 0;
  150. BYTE *lpTemp = NULL;
  151. m_dpConnection.ConnectId = (long)msg->hConnectId;
  152. // Let's load our SafeArray
  153. if (msg->dwLobbyConnectDataSize)
  154. {
  155. rgsabound[0].lLbound = 0;
  156. rgsabound[0].cElements = msg->dwLobbyConnectDataSize;
  157. lpData = SafeArrayCreate(VT_UI1, 1, rgsabound);
  158. lpTemp = (BYTE*)lpData->pvData;
  159. lpData->pvData = msg->pvLobbyConnectData;
  160. m_dpConnection.LobbyConnectData = lpData;
  161. }
  162. lpPeer->GetVBConnSettings(msg->pdplConnectionSettings, &m_dpConnection.dplMsgCon);
  163. __try {
  164. hr = msg->pdplConnectionSettings->pdp8HostAddress->GetURLW(NULL, &dwNumChars);
  165. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  166. return hr;
  167. if (FAILED (hr = msg->pdplConnectionSettings->pdp8HostAddress->GetURLW(&wszAddress[0],&dwNumChars) ) )
  168. return hr;
  169. m_dpConnection.dplMsgCon.AddressSenderUrl = SysAllocString(wszAddress);
  170. }
  171. __except(EXCEPTION_EXECUTE_HANDLER)
  172. {
  173. // Just skip this part
  174. }
  175. __try {
  176. dwNumChars = 0;
  177. hr = ((IDirectPlay8Address*)*msg->pdplConnectionSettings->ppdp8DeviceAddresses)->GetURLW(NULL, &dwNumChars);
  178. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  179. return hr;
  180. if (FAILED (hr = ((IDirectPlay8Address*)*msg->pdplConnectionSettings->ppdp8DeviceAddresses)->GetURLW(&wszDevice[0],&dwNumChars) ) )
  181. return hr;
  182. m_dpConnection.dplMsgCon.AddressDeviceUrl = SysAllocString(wszDevice);
  183. }
  184. __except(EXCEPTION_EXECUTE_HANDLER)
  185. {
  186. // Just skip this part
  187. }
  188. lpEvent->Connect(&m_dpConnection, &fRejectMsg);
  189. if (lpData) //Get rid of the safearray
  190. {
  191. lpData->pvData = lpTemp;
  192. SafeArrayDestroy(lpData);
  193. }
  194. // Get rid of these addresses
  195. if (m_dpConnection.dplMsgCon.AddressSenderUrl)
  196. SysFreeString(m_dpConnection.dplMsgCon.AddressSenderUrl);
  197. if (m_dpConnection.dplMsgCon.AddressDeviceUrl)
  198. SysFreeString(m_dpConnection.dplMsgCon.AddressDeviceUrl);
  199. break;
  200. }
  201. //Disconnect
  202. case DPL_MSGID_DISCONNECT:
  203. {
  204. DPL_MESSAGE_DISCONNECT *msg = (DPL_MESSAGE_DISCONNECT*)pMsgBuffer;
  205. DPNHANDLE m_hDisconnectID;
  206. HRESULT m_hDisconnectReason;
  207. m_hDisconnectID = (long)msg->hDisconnectId;
  208. m_hDisconnectReason = (long) msg->hrReason;
  209. lpEvent->Disconnect(m_hDisconnectID, m_hDisconnectReason);
  210. break;
  211. }
  212. //Status
  213. case DPL_MSGID_SESSION_STATUS:
  214. {
  215. DPL_MESSAGE_SESSION_STATUS *msg = (DPL_MESSAGE_SESSION_STATUS*)pMsgBuffer;
  216. DPNHANDLE m_hSender;
  217. DWORD m_dwSessionStatus;
  218. m_dwSessionStatus = (long)msg->dwStatus;
  219. m_hSender = (long)msg->hSender;
  220. lpEvent->SessionStatus(m_dwSessionStatus,m_hSender);
  221. break;
  222. }
  223. //ConnectionSettings
  224. case DPL_MSGID_CONNECTION_SETTINGS:
  225. {
  226. DPL_MESSAGE_CONNECTION_SETTINGS *msg = (DPL_MESSAGE_CONNECTION_SETTINGS*)pMsgBuffer;
  227. DPL_MESSAGE_CONNECTION_SETTINGS_CDESC dpCon;
  228. WCHAR wszAddress[MAX_PATH];
  229. WCHAR wszDevice[MAX_PATH];
  230. DWORD dwNumChars = 0;
  231. ZeroMemory(&dpCon, sizeof(DPL_MESSAGE_CONNECTION_SETTINGS_CDESC));
  232. lpPeer->GetVBConnSettings(msg->pdplConnectionSettings, &dpCon.dplConnectionSettings);
  233. dpCon.hSender = (long)msg->hSender;
  234. __try {
  235. hr = msg->pdplConnectionSettings->pdp8HostAddress->GetURLW(NULL, &dwNumChars);
  236. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  237. return hr;
  238. if (FAILED (hr = msg->pdplConnectionSettings->pdp8HostAddress->GetURLW(&wszAddress[0],&dwNumChars) ) )
  239. return hr;
  240. dpCon.dplConnectionSettings.AddressSenderUrl = SysAllocString(wszAddress);
  241. }
  242. __except(EXCEPTION_EXECUTE_HANDLER)
  243. {
  244. // Just skip this part
  245. }
  246. __try {
  247. dwNumChars = 0;
  248. hr = ((IDirectPlay8Address*)*msg->pdplConnectionSettings->ppdp8DeviceAddresses)->GetURLW(NULL, &dwNumChars);
  249. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  250. return hr;
  251. if (FAILED (hr = ((IDirectPlay8Address*)*msg->pdplConnectionSettings->ppdp8DeviceAddresses)->GetURLW(&wszDevice[0],&dwNumChars) ) )
  252. return hr;
  253. dpCon.dplConnectionSettings.AddressDeviceUrl = SysAllocString(wszDevice);
  254. }
  255. __except(EXCEPTION_EXECUTE_HANDLER)
  256. {
  257. // Just skip this part
  258. }
  259. lpEvent->ConnectionSettings(&dpCon);
  260. // Get rid of these addresses
  261. if (dpCon.dplConnectionSettings.AddressSenderUrl)
  262. SysFreeString(dpCon.dplConnectionSettings.AddressSenderUrl);
  263. if (dpCon.dplConnectionSettings.AddressDeviceUrl)
  264. SysFreeString(dpCon.dplConnectionSettings.AddressDeviceUrl);
  265. break;
  266. }
  267. }
  268. __try {
  269. if (lpPeer->m_pEventStream)
  270. // clean up marshaled packet
  271. CoReleaseMarshalData(lpPeer->m_pEventStream);
  272. }
  273. __except(EXCEPTION_EXECUTE_HANDLER)
  274. {
  275. lpPeer->m_fHandleEvents = FALSE;
  276. return S_OK;
  277. }
  278. if (fCallCoUninit)
  279. CoUninitialize();
  280. DPF(1,"-----Leaving (DPlayLobbyClient) MessageHandler call...\n");
  281. if (fRejectMsg != VARIANT_FALSE)
  282. return E_FAIL;
  283. return S_OK;
  284. }
  285. HRESULT C_dxj_DirectPlayLobbyClientObject::RegisterMessageHandler(I_dxj_DirectPlayLobbyEvent *lobbyEvent)
  286. {
  287. HRESULT hr=S_OK;
  288. LPSTREAM pStm=NULL;
  289. DPF(1,"-----Entering (DPlayLobbyClient) RegisterMessageHandler call...\n");
  290. if (!lobbyEvent) return E_INVALIDARG;
  291. if (!m_fHandleEvents)
  292. {
  293. if (m_pEventStream)
  294. m_pEventStream->Release();
  295. // Create a global stream. The stream needs to be global so we can
  296. // marshal once, and unmarshal as many times as necessary
  297. hr = CreateStreamOnHGlobal(NULL, TRUE, &pStm);
  298. if FAILED(hr) return hr;
  299. // Now we can marshal our IUnknown interface. We use MSHLFLAGS_TABLEWEAK
  300. // so we can unmarshal any number of times
  301. hr = CoMarshalInterface(pStm, IID_I_dxj_DirectPlayLobbyEvent, lobbyEvent, MSHCTX_INPROC, NULL, MSHLFLAGS_TABLEWEAK);
  302. if FAILED(hr) return hr;
  303. // Now we need to set the seek location of the stream to the beginning
  304. LARGE_INTEGER l;
  305. l.QuadPart = 0;
  306. pStm->Seek(l, STREAM_SEEK_SET, NULL);
  307. m_pEventStream=pStm;
  308. if (!m_fInit)
  309. {
  310. if (FAILED ( hr = m__dxj_DirectPlayLobbyClient->Initialize( this, DirectPlayLobbyClientMessageHandler, 0 ) ) )
  311. return hr;
  312. m_fInit = TRUE;
  313. }
  314. m_fHandleEvents = TRUE;
  315. }
  316. else
  317. return DPNERR_ALREADYINITIALIZED;
  318. return hr;
  319. }
  320. HRESULT C_dxj_DirectPlayLobbyClientObject::GetCountLocalPrograms(BSTR GuidApplication,long *lCount)
  321. {
  322. GUID *guidApp = NULL;
  323. HRESULT hr;
  324. __try {
  325. DPF(1,"-----Entering (DPlayLobbyClient) GetCountLocalPrograms call...\n");
  326. if (!IsEmptyString(GuidApplication))
  327. {
  328. guidApp = new GUID;
  329. if (FAILED (hr = BSTRtoGUID(guidApp,GuidApplication) ) )
  330. return hr;
  331. }
  332. if (FAILED (hr = GetProgs(guidApp) ) )
  333. return hr;
  334. if (guidApp)
  335. SAFE_DELETE(guidApp);
  336. *lCount = (long)m_dwAppCount;
  337. }
  338. __except(EXCEPTION_EXECUTE_HANDLER)
  339. {
  340. return E_FAIL;
  341. }
  342. return S_OK;
  343. }
  344. HRESULT C_dxj_DirectPlayLobbyClientObject::GetLocalProgram(long lProgID, DPL_APPLICATION_INFO_CDESC *app)
  345. {
  346. __try {
  347. DPF(1,"-----Entering (DPlayLobbyClient) GetLocalProgram call...\n");
  348. if (!m_ProgInfo)
  349. return E_INVALIDARG;
  350. if ((lProgID < 1 ) || ((DWORD)lProgID > m_dwAppCount))
  351. return E_INVALIDARG;
  352. // Now we've got to fill our DPL_PROGRAM_DESC_CDESC structure
  353. //app->lSize = m_ProgInfo[lProgID - 1].dwSize;
  354. app->lFlags = m_ProgInfo[lProgID - 1].dwFlags;
  355. app->ApplicationName = SysAllocString(m_ProgInfo[lProgID - 1].pwszApplicationName);
  356. app->guidApplication = GUIDtoBSTR(&m_ProgInfo[lProgID - 1].guidApplication);
  357. app->lNumRunning = m_ProgInfo[lProgID - 1].dwNumRunning;
  358. app->lNumWaiting = m_ProgInfo[lProgID - 1].dwNumWaiting;
  359. }
  360. __except(EXCEPTION_EXECUTE_HANDLER)
  361. {
  362. return E_FAIL;
  363. }
  364. return S_OK;
  365. }
  366. HRESULT C_dxj_DirectPlayLobbyClientObject::ConnectApplication(DPL_CONNECT_INFO_CDESC *ConnectionInfo,long lTimeOut,long lFlags, long *hApplication)
  367. {
  368. HRESULT hr;
  369. DPL_CONNECT_INFO dplConnect;
  370. DPNHANDLE hApp = NULL;
  371. __try {
  372. DPF(1,"-----Entering (DPlayLobbyClient) ConnectApplication call...\n");
  373. ZeroMemory(&dplConnect,sizeof(DPL_CONNECT_INFO));
  374. // Fill out our connection structure
  375. dplConnect.dwSize = sizeof(DPL_CONNECT_INFO);
  376. dplConnect.dwFlags = ConnectionInfo->lFlags;
  377. if (FAILED (hr = BSTRtoGUID(&dplConnect.guidApplication,ConnectionInfo->guidApplication) ) )
  378. return hr;
  379. if (FAILED (hr = m__dxj_DirectPlayLobbyClient->ConnectApplication(&dplConnect,NULL, &hApp, (DWORD) lTimeOut, (DWORD) lFlags) ) )
  380. return hr;
  381. *hApplication = (long)hApp;
  382. }
  383. __except(EXCEPTION_EXECUTE_HANDLER)
  384. {
  385. return E_FAIL;
  386. }
  387. return S_OK;
  388. }
  389. HRESULT C_dxj_DirectPlayLobbyClientObject::Send(long Target,SAFEARRAY **Buffer,long lBufferSize,long lFlags)
  390. {
  391. HRESULT hr;
  392. BYTE *lpBuf = NULL;
  393. DWORD dwBufferSize = 0;
  394. __try {
  395. DPF(1,"-----Entering (DPlayLobbyClient) Send call...\n");
  396. dwBufferSize = (DWORD)lBufferSize;
  397. hr = m__dxj_DirectPlayLobbyClient->Send((DPNHANDLE) Target, (BYTE*) ((SAFEARRAY*)*Buffer)->pvData, dwBufferSize, (DWORD) lFlags);
  398. if ((hr != DPNERR_PENDING) && FAILED(hr))
  399. return hr;
  400. }
  401. __except(EXCEPTION_EXECUTE_HANDLER)
  402. {
  403. return E_FAIL;
  404. }
  405. return S_OK;
  406. }
  407. HRESULT C_dxj_DirectPlayLobbyClientObject::ReleaseApplication(long Application)
  408. {
  409. HRESULT hr;
  410. __try {
  411. DPF(1,"-----Entering (DPlayLobbyClient) ReleaseApplication call...\n");
  412. if (FAILED (hr = m__dxj_DirectPlayLobbyClient->ReleaseApplication( (DPNHANDLE) Application, 0 ) ) )
  413. return hr;
  414. }
  415. __except(EXCEPTION_EXECUTE_HANDLER)
  416. {
  417. return E_FAIL;
  418. }
  419. return S_OK;
  420. }
  421. HRESULT C_dxj_DirectPlayLobbyClientObject::Close()
  422. {
  423. HRESULT hr;
  424. BOOL bGotMsg = FALSE;
  425. BOOL bWait = FALSE;
  426. DWORD dwObj = 0;
  427. int i=0;
  428. MSG msg;
  429. __try {
  430. DPF(1,"-----Entering (DPlayLobbyClient) Close call...\n");
  431. HANDLE hThread = NULL;
  432. DWORD dwThread = 0;
  433. hThread = CreateThread(NULL, 0, &CloseLobbyClientThreadProc, this->m__dxj_DirectPlayLobbyClient, 0, &dwThread);
  434. msg.message = WM_NULL;
  435. while ((WM_QUIT != msg.message) && (!bWait))
  436. {
  437. bGotMsg = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);
  438. i++;
  439. if ((!bGotMsg) || (i>10))
  440. {
  441. dwObj = WaitForSingleObject(hThread, 10);
  442. bWait = (dwObj == WAIT_OBJECT_0);
  443. i = 0;
  444. }
  445. if (bGotMsg)
  446. {
  447. TranslateMessage( &msg );
  448. DispatchMessage( &msg );
  449. }
  450. bGotMsg = FALSE;
  451. }
  452. }
  453. __except(EXCEPTION_EXECUTE_HANDLER)
  454. {
  455. return E_FAIL;
  456. }
  457. return S_OK;
  458. }
  459. HRESULT C_dxj_DirectPlayLobbyClientObject::GetProgs(GUID *guidApp)
  460. {
  461. // Enumerate all DirectPlay Local Progs
  462. HRESULT hr;
  463. DWORD dwSize=0;
  464. DWORD dwItems=0;
  465. __try {
  466. DPF(1,"-----Entering (DPlayLobbyClient) GetProgs call...\n");
  467. hr = m__dxj_DirectPlayLobbyClient->EnumLocalPrograms( guidApp, (BYTE*)m_ProgInfo, &dwSize, &dwItems, 0);
  468. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  469. return hr;
  470. m_ProgInfo = (DPL_APPLICATION_INFO*) new BYTE[dwSize];
  471. if( FAILED( hr = m__dxj_DirectPlayLobbyClient->EnumLocalPrograms( guidApp, (BYTE*)m_ProgInfo, &dwSize, &dwItems, 0) ) )
  472. return hr;
  473. m_dwAppCount = dwItems;
  474. }
  475. __except(EXCEPTION_EXECUTE_HANDLER)
  476. {
  477. return E_FAIL;
  478. }
  479. return S_OK;
  480. }
  481. HRESULT C_dxj_DirectPlayLobbyClientObject::UnRegisterMessageHandler()
  482. {
  483. DPF(1,"-----Entering (DPlayLobbyClient) UnregisterMessageHandler call...\n");
  484. m_fHandleEvents = FALSE;
  485. return S_OK;
  486. }
  487. HRESULT C_dxj_DirectPlayLobbyClientObject::GetConnectionSettings(long hLobbyClient, long lFlags, DPL_CONNECTION_SETTINGS_CDESC *ConnectionSettings)
  488. {
  489. DPL_CONNECTION_SETTINGS *desc = NULL;
  490. DWORD dwSize = 0;
  491. HRESULT hr = S_OK;
  492. WCHAR wszAddress[MAX_PATH];
  493. WCHAR wszDevice[MAX_PATH];
  494. DWORD dwNumChars = 0;
  495. __try {
  496. hr= m__dxj_DirectPlayLobbyClient->GetConnectionSettings((DPNHANDLE) hLobbyClient, NULL, &dwSize, (DWORD) lFlags);
  497. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  498. return hr;
  499. desc = (DPL_CONNECTION_SETTINGS*)new BYTE[dwSize];
  500. desc->dwSize = sizeof(DPL_CONNECTION_SETTINGS);
  501. hr= m__dxj_DirectPlayLobbyClient->GetConnectionSettings((DPNHANDLE) hLobbyClient, desc, &dwSize, (DWORD) lFlags);
  502. if( FAILED(hr))
  503. return hr;
  504. __try {
  505. hr = desc->pdp8HostAddress->GetURLW(NULL, &dwNumChars);
  506. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  507. return hr;
  508. if (FAILED (hr = desc->pdp8HostAddress->GetURLW(&wszAddress[0],&dwNumChars) ) )
  509. return hr;
  510. ConnectionSettings->AddressSenderUrl = SysAllocString(wszAddress);
  511. }
  512. __except(EXCEPTION_EXECUTE_HANDLER)
  513. {
  514. // Just skip this part
  515. }
  516. __try {
  517. dwNumChars = 0;
  518. hr = ((IDirectPlay8Address*)*desc->ppdp8DeviceAddresses)->GetURLW(NULL, &dwNumChars);
  519. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  520. return hr;
  521. if (FAILED (hr = ((IDirectPlay8Address*)*desc->ppdp8DeviceAddresses)->GetURLW(&wszDevice[0],&dwNumChars) ) )
  522. return hr;
  523. ConnectionSettings->AddressDeviceUrl = SysAllocString(wszDevice);
  524. }
  525. __except(EXCEPTION_EXECUTE_HANDLER)
  526. {
  527. // Just skip this part
  528. }
  529. GetVBConnSettings(desc, ConnectionSettings);
  530. }
  531. __except(EXCEPTION_EXECUTE_HANDLER)
  532. {
  533. return E_FAIL;
  534. }
  535. return S_OK;
  536. }
  537. HRESULT C_dxj_DirectPlayLobbyClientObject::SetConnectionSettings(long hTarget, long lFlags, DPL_CONNECTION_SETTINGS_CDESC *ConnectionSettings, I_dxj_DirectPlayAddress *HostAddress, I_dxj_DirectPlayAddress *Device)
  538. {
  539. DPL_CONNECTION_SETTINGS desc;
  540. HRESULT hr = S_OK;
  541. GUID guidApp;
  542. GUID guidInst;
  543. WCHAR wszSessionName[MAX_PATH];
  544. WCHAR wszPassword[MAX_PATH];
  545. __try {
  546. ZeroMemory(&desc, sizeof(DPL_CONNECTION_SETTINGS));
  547. desc.dwSize = sizeof(DPL_CONNECTION_SETTINGS);
  548. desc.dwFlags = ConnectionSettings->lFlags;
  549. HostAddress->InternalGetObject((IUnknown**)&desc.pdp8HostAddress);
  550. Device->InternalGetObject((IUnknown**)desc.ppdp8DeviceAddresses);
  551. ZeroMemory(&desc.dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
  552. // Set up our Desc
  553. desc.dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
  554. if (!IsEmptyString(ConnectionSettings->ApplicationDescription.SessionName))
  555. {
  556. wcscpy(wszSessionName,ConnectionSettings->ApplicationDescription.SessionName);
  557. desc.dpnAppDesc.pwszSessionName = wszSessionName;
  558. }
  559. if (!IsEmptyString(ConnectionSettings->ApplicationDescription.Password))
  560. {
  561. wcscpy(wszPassword,ConnectionSettings->ApplicationDescription.Password);
  562. desc.dpnAppDesc.pwszPassword = wszPassword;
  563. }
  564. desc.dpnAppDesc.dwFlags = ConnectionSettings->ApplicationDescription.lFlags;
  565. desc.dpnAppDesc.dwMaxPlayers = ConnectionSettings->ApplicationDescription.lMaxPlayers;
  566. desc.dpnAppDesc.dwCurrentPlayers = ConnectionSettings->ApplicationDescription.lCurrentPlayers;
  567. if (FAILED(hr = DPLAYBSTRtoGUID(&guidApp, ConnectionSettings->ApplicationDescription.guidApplication) ) )
  568. return hr;
  569. desc.dpnAppDesc.guidApplication = guidApp;
  570. if (FAILED(hr = DPLAYBSTRtoGUID(&guidInst, ConnectionSettings->ApplicationDescription.guidInstance) ) )
  571. return hr;
  572. desc.dpnAppDesc.guidInstance = guidInst;
  573. hr= m__dxj_DirectPlayLobbyClient->SetConnectionSettings((DPNHANDLE) hTarget, &desc, (DWORD) lFlags);
  574. if( FAILED(hr))
  575. return hr;
  576. }
  577. __except(EXCEPTION_EXECUTE_HANDLER)
  578. {
  579. return E_FAIL;
  580. }
  581. return S_OK;
  582. }
  583. HRESULT C_dxj_DirectPlayLobbyClientObject::GetVBConnSettings(DPL_CONNECTION_SETTINGS *OldCon, DPL_CONNECTION_SETTINGS_CDESC *NewCon)
  584. {
  585. IDirectPlay8Address *dpAdd = NULL;
  586. HRESULT hr;
  587. __try {
  588. NewCon->lSize = OldCon->dwSize;
  589. NewCon->lFlags = OldCon->dwFlags;
  590. NewCon->PlayerName = SysAllocString(OldCon->pwszPlayerName);
  591. ZeroMemory(&NewCon->ApplicationDescription, sizeof(DPN_APPLICATION_DESC_CDESC));
  592. // Set up our Desc
  593. NewCon->ApplicationDescription.lSize = OldCon->dpnAppDesc.dwSize;
  594. NewCon->ApplicationDescription.SessionName = SysAllocString(OldCon->dpnAppDesc.pwszSessionName);
  595. NewCon->ApplicationDescription.Password = SysAllocString(OldCon->dpnAppDesc.pwszPassword);
  596. NewCon->ApplicationDescription.lFlags = OldCon->dpnAppDesc.dwFlags;
  597. NewCon->ApplicationDescription.lMaxPlayers = OldCon->dpnAppDesc.dwMaxPlayers;
  598. NewCon->ApplicationDescription.lCurrentPlayers = OldCon->dpnAppDesc.dwCurrentPlayers;
  599. NewCon->ApplicationDescription.guidApplication = GUIDtoBSTR(&OldCon->dpnAppDesc.guidApplication);
  600. NewCon->ApplicationDescription.guidInstance = GUIDtoBSTR(&OldCon->dpnAppDesc.guidInstance);
  601. }
  602. __except(EXCEPTION_EXECUTE_HANDLER)
  603. {
  604. return E_FAIL;
  605. }
  606. return S_OK;
  607. }
  608. DWORD WINAPI CloseLobbyClientThreadProc(void* lpParam)
  609. {
  610. // User context for the message handler is a pointer to our class module.
  611. IDirectPlay8LobbyClient *lpPeer = (IDirectPlay8LobbyClient*)lpParam;
  612. DPF(1,"-----Entering (DPlayLobbiedApp) ClosePeerThreadProc call...\n");
  613. lpPeer->Close(0);
  614. DPF(1,"-----Leaving (DPlayLobbiedApp) ClosePeerThreadProc call ...\n");
  615. return 0;
  616. }