Leaked source code of windows server 2003
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.

767 lines
23 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_CDESC));
  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 = NULL;
  148. WCHAR* wszDevice = NULL;
  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. wszAddress = (WCHAR*)_alloca(sizeof(WCHAR) * dwNumChars);
  168. if (FAILED (hr = msg->pdplConnectionSettings->pdp8HostAddress->GetURLW(wszAddress,&dwNumChars) ) )
  169. return hr;
  170. m_dpConnection.dplMsgCon.AddressSenderUrl = SysAllocString(wszAddress);
  171. }
  172. __except(EXCEPTION_EXECUTE_HANDLER)
  173. {
  174. // Just skip this part
  175. }
  176. __try {
  177. dwNumChars = 0;
  178. hr = ((IDirectPlay8Address*)*msg->pdplConnectionSettings->ppdp8DeviceAddresses)->GetURLW(NULL, &dwNumChars);
  179. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  180. return hr;
  181. wszDevice = (WCHAR*)_alloca(sizeof(WCHAR) * dwNumChars);
  182. if (FAILED (hr = ((IDirectPlay8Address*)*msg->pdplConnectionSettings->ppdp8DeviceAddresses)->GetURLW(wszDevice,&dwNumChars) ) )
  183. return hr;
  184. m_dpConnection.dplMsgCon.AddressDeviceUrl = SysAllocString(wszDevice);
  185. }
  186. __except(EXCEPTION_EXECUTE_HANDLER)
  187. {
  188. // Just skip this part
  189. }
  190. lpEvent->Connect(&m_dpConnection, &fRejectMsg);
  191. if (lpData) //Get rid of the safearray
  192. {
  193. lpData->pvData = lpTemp;
  194. SafeArrayDestroy(lpData);
  195. }
  196. // Get rid of these addresses
  197. if (m_dpConnection.dplMsgCon.AddressSenderUrl)
  198. SysFreeString(m_dpConnection.dplMsgCon.AddressSenderUrl);
  199. if (m_dpConnection.dplMsgCon.AddressDeviceUrl)
  200. SysFreeString(m_dpConnection.dplMsgCon.AddressDeviceUrl);
  201. break;
  202. }
  203. //Disconnect
  204. case DPL_MSGID_DISCONNECT:
  205. {
  206. DPL_MESSAGE_DISCONNECT *msg = (DPL_MESSAGE_DISCONNECT*)pMsgBuffer;
  207. DPNHANDLE m_hDisconnectID;
  208. HRESULT m_hDisconnectReason;
  209. m_hDisconnectID = (long)msg->hDisconnectId;
  210. m_hDisconnectReason = (long) msg->hrReason;
  211. lpEvent->Disconnect(m_hDisconnectID, m_hDisconnectReason);
  212. break;
  213. }
  214. //Status
  215. case DPL_MSGID_SESSION_STATUS:
  216. {
  217. DPL_MESSAGE_SESSION_STATUS *msg = (DPL_MESSAGE_SESSION_STATUS*)pMsgBuffer;
  218. DPNHANDLE m_hSender;
  219. DWORD m_dwSessionStatus;
  220. m_dwSessionStatus = (long)msg->dwStatus;
  221. m_hSender = (long)msg->hSender;
  222. lpEvent->SessionStatus(m_dwSessionStatus,m_hSender);
  223. break;
  224. }
  225. //ConnectionSettings
  226. case DPL_MSGID_CONNECTION_SETTINGS:
  227. {
  228. DPL_MESSAGE_CONNECTION_SETTINGS *msg = (DPL_MESSAGE_CONNECTION_SETTINGS*)pMsgBuffer;
  229. DPL_MESSAGE_CONNECTION_SETTINGS_CDESC dpCon;
  230. WCHAR* wszAddress = NULL;
  231. WCHAR* wszDevice = NULL;
  232. DWORD dwNumChars = 0;
  233. ZeroMemory(&dpCon, sizeof(DPL_MESSAGE_CONNECTION_SETTINGS_CDESC));
  234. lpPeer->GetVBConnSettings(msg->pdplConnectionSettings, &dpCon.dplConnectionSettings);
  235. dpCon.hSender = (long)msg->hSender;
  236. __try {
  237. hr = msg->pdplConnectionSettings->pdp8HostAddress->GetURLW(NULL, &dwNumChars);
  238. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  239. return hr;
  240. wszAddress = (WCHAR*)_alloca(sizeof(WCHAR) * dwNumChars);
  241. if (FAILED (hr = msg->pdplConnectionSettings->pdp8HostAddress->GetURLW(wszAddress,&dwNumChars) ) )
  242. return hr;
  243. dpCon.dplConnectionSettings.AddressSenderUrl = SysAllocString(wszAddress);
  244. }
  245. __except(EXCEPTION_EXECUTE_HANDLER)
  246. {
  247. // Just skip this part
  248. }
  249. __try {
  250. dwNumChars = 0;
  251. hr = ((IDirectPlay8Address*)*msg->pdplConnectionSettings->ppdp8DeviceAddresses)->GetURLW(NULL, &dwNumChars);
  252. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  253. return hr;
  254. wszDevice = (WCHAR*)_alloca(sizeof(WCHAR) * dwNumChars);
  255. if (FAILED (hr = ((IDirectPlay8Address*)*msg->pdplConnectionSettings->ppdp8DeviceAddresses)->GetURLW(wszDevice,&dwNumChars) ) )
  256. return hr;
  257. dpCon.dplConnectionSettings.AddressDeviceUrl = SysAllocString(wszDevice);
  258. }
  259. __except(EXCEPTION_EXECUTE_HANDLER)
  260. {
  261. // Just skip this part
  262. }
  263. lpEvent->ConnectionSettings(&dpCon);
  264. // Get rid of these addresses
  265. if (dpCon.dplConnectionSettings.AddressSenderUrl)
  266. SysFreeString(dpCon.dplConnectionSettings.AddressSenderUrl);
  267. if (dpCon.dplConnectionSettings.AddressDeviceUrl)
  268. SysFreeString(dpCon.dplConnectionSettings.AddressDeviceUrl);
  269. break;
  270. }
  271. }
  272. __try {
  273. if (lpPeer->m_pEventStream)
  274. // clean up marshaled packet
  275. CoReleaseMarshalData(lpPeer->m_pEventStream);
  276. }
  277. __except(EXCEPTION_EXECUTE_HANDLER)
  278. {
  279. lpPeer->m_fHandleEvents = FALSE;
  280. return S_OK;
  281. }
  282. if (fCallCoUninit)
  283. CoUninitialize();
  284. DPF(1,"-----Leaving (DPlayLobbyClient) MessageHandler call...\n");
  285. if (fRejectMsg != VARIANT_FALSE)
  286. return E_FAIL;
  287. return S_OK;
  288. }
  289. HRESULT C_dxj_DirectPlayLobbyClientObject::RegisterMessageHandler(I_dxj_DirectPlayLobbyEvent *lobbyEvent)
  290. {
  291. HRESULT hr=S_OK;
  292. LPSTREAM pStm=NULL;
  293. DPF(1,"-----Entering (DPlayLobbyClient) RegisterMessageHandler call...\n");
  294. if (!lobbyEvent) return E_INVALIDARG;
  295. if (!m_fHandleEvents)
  296. {
  297. if (m_pEventStream)
  298. m_pEventStream->Release();
  299. // Create a global stream. The stream needs to be global so we can
  300. // marshal once, and unmarshal as many times as necessary
  301. hr = CreateStreamOnHGlobal(NULL, TRUE, &pStm);
  302. if FAILED(hr) return hr;
  303. // Now we can marshal our IUnknown interface. We use MSHLFLAGS_TABLEWEAK
  304. // so we can unmarshal any number of times
  305. hr = CoMarshalInterface(pStm, IID_I_dxj_DirectPlayLobbyEvent, lobbyEvent, MSHCTX_INPROC, NULL, MSHLFLAGS_TABLEWEAK);
  306. if FAILED(hr) return hr;
  307. // Now we need to set the seek location of the stream to the beginning
  308. LARGE_INTEGER l;
  309. l.QuadPart = 0;
  310. pStm->Seek(l, STREAM_SEEK_SET, NULL);
  311. m_pEventStream=pStm;
  312. if (!m_fInit)
  313. {
  314. if (FAILED ( hr = m__dxj_DirectPlayLobbyClient->Initialize( this, DirectPlayLobbyClientMessageHandler, 0 ) ) )
  315. return hr;
  316. m_fInit = TRUE;
  317. }
  318. m_fHandleEvents = TRUE;
  319. }
  320. else
  321. return DPNERR_ALREADYINITIALIZED;
  322. return hr;
  323. }
  324. HRESULT C_dxj_DirectPlayLobbyClientObject::GetCountLocalPrograms(BSTR GuidApplication,long *lCount)
  325. {
  326. GUID *guidApp = NULL;
  327. HRESULT hr;
  328. __try {
  329. DPF(1,"-----Entering (DPlayLobbyClient) GetCountLocalPrograms call...\n");
  330. if (!IsEmptyString(GuidApplication))
  331. {
  332. guidApp = new GUID;
  333. if (FAILED (hr = BSTRtoGUID(guidApp,GuidApplication) ) )
  334. return hr;
  335. }
  336. if (FAILED (hr = GetProgs(guidApp) ) )
  337. return hr;
  338. if (guidApp)
  339. SAFE_DELETE(guidApp);
  340. *lCount = (long)m_dwAppCount;
  341. }
  342. __except(EXCEPTION_EXECUTE_HANDLER)
  343. {
  344. return E_FAIL;
  345. }
  346. return S_OK;
  347. }
  348. HRESULT C_dxj_DirectPlayLobbyClientObject::GetLocalProgram(long lProgID, DPL_APPLICATION_INFO_CDESC *app)
  349. {
  350. __try {
  351. DPF(1,"-----Entering (DPlayLobbyClient) GetLocalProgram call...\n");
  352. if (!m_ProgInfo)
  353. return E_INVALIDARG;
  354. if ((lProgID < 1 ) || ((DWORD)lProgID > m_dwAppCount))
  355. return E_INVALIDARG;
  356. // Now we've got to fill our DPL_PROGRAM_DESC_CDESC structure
  357. //app->lSize = m_ProgInfo[lProgID - 1].dwSize;
  358. app->lFlags = m_ProgInfo[lProgID - 1].dwFlags;
  359. app->ApplicationName = SysAllocString(m_ProgInfo[lProgID - 1].pwszApplicationName);
  360. app->guidApplication = GUIDtoBSTR(&m_ProgInfo[lProgID - 1].guidApplication);
  361. app->lNumRunning = m_ProgInfo[lProgID - 1].dwNumRunning;
  362. app->lNumWaiting = m_ProgInfo[lProgID - 1].dwNumWaiting;
  363. }
  364. __except(EXCEPTION_EXECUTE_HANDLER)
  365. {
  366. return E_FAIL;
  367. }
  368. return S_OK;
  369. }
  370. HRESULT C_dxj_DirectPlayLobbyClientObject::ConnectApplication(DPL_CONNECT_INFO_CDESC *ConnectionInfo,long lTimeOut,long lFlags, long *hApplication)
  371. {
  372. HRESULT hr;
  373. DPL_CONNECT_INFO dplConnect;
  374. DPNHANDLE hApp = NULL;
  375. __try {
  376. DPF(1,"-----Entering (DPlayLobbyClient) ConnectApplication call...\n");
  377. ZeroMemory(&dplConnect,sizeof(DPL_CONNECT_INFO));
  378. // Fill out our connection structure
  379. dplConnect.dwSize = sizeof(DPL_CONNECT_INFO);
  380. dplConnect.dwFlags = ConnectionInfo->lFlags;
  381. if (FAILED (hr = BSTRtoGUID(&dplConnect.guidApplication,ConnectionInfo->guidApplication) ) )
  382. return hr;
  383. if (FAILED (hr = m__dxj_DirectPlayLobbyClient->ConnectApplication(&dplConnect,NULL, &hApp, (DWORD) lTimeOut, (DWORD) lFlags) ) )
  384. return hr;
  385. *hApplication = (long)hApp;
  386. }
  387. __except(EXCEPTION_EXECUTE_HANDLER)
  388. {
  389. return E_FAIL;
  390. }
  391. return S_OK;
  392. }
  393. HRESULT C_dxj_DirectPlayLobbyClientObject::Send(long Target,SAFEARRAY **Buffer,long lBufferSize,long lFlags)
  394. {
  395. HRESULT hr;
  396. BYTE *lpBuf = NULL;
  397. DWORD dwBufferSize = 0;
  398. __try {
  399. DPF(1,"-----Entering (DPlayLobbyClient) Send call...\n");
  400. dwBufferSize = (DWORD)lBufferSize;
  401. hr = m__dxj_DirectPlayLobbyClient->Send((DPNHANDLE) Target, (BYTE*) ((SAFEARRAY*)*Buffer)->pvData, dwBufferSize, (DWORD) lFlags);
  402. if ((hr != DPNERR_PENDING) && FAILED(hr))
  403. return hr;
  404. }
  405. __except(EXCEPTION_EXECUTE_HANDLER)
  406. {
  407. return E_FAIL;
  408. }
  409. return S_OK;
  410. }
  411. HRESULT C_dxj_DirectPlayLobbyClientObject::ReleaseApplication(long Application)
  412. {
  413. HRESULT hr;
  414. __try {
  415. DPF(1,"-----Entering (DPlayLobbyClient) ReleaseApplication call...\n");
  416. if (FAILED (hr = m__dxj_DirectPlayLobbyClient->ReleaseApplication( (DPNHANDLE) Application, 0 ) ) )
  417. return hr;
  418. }
  419. __except(EXCEPTION_EXECUTE_HANDLER)
  420. {
  421. return E_FAIL;
  422. }
  423. return S_OK;
  424. }
  425. HRESULT C_dxj_DirectPlayLobbyClientObject::Close()
  426. {
  427. HRESULT hr;
  428. BOOL bGotMsg = FALSE;
  429. BOOL bWait = FALSE;
  430. DWORD dwObj = 0;
  431. int i=0;
  432. MSG msg;
  433. __try {
  434. DPF(1,"-----Entering (DPlayLobbyClient) Close call...\n");
  435. HANDLE hThread = NULL;
  436. DWORD dwThread = 0;
  437. hThread = CreateThread(NULL, 0, &CloseLobbyClientThreadProc, this->m__dxj_DirectPlayLobbyClient, 0, &dwThread);
  438. msg.message = WM_NULL;
  439. while ((WM_QUIT != msg.message) && (!bWait))
  440. {
  441. bGotMsg = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);
  442. i++;
  443. if ((!bGotMsg) || (i>10))
  444. {
  445. dwObj = WaitForSingleObject(hThread, 10);
  446. bWait = (dwObj == WAIT_OBJECT_0);
  447. i = 0;
  448. }
  449. if (bGotMsg)
  450. {
  451. TranslateMessage( &msg );
  452. DispatchMessage( &msg );
  453. }
  454. bGotMsg = FALSE;
  455. }
  456. }
  457. __except(EXCEPTION_EXECUTE_HANDLER)
  458. {
  459. return E_FAIL;
  460. }
  461. return S_OK;
  462. }
  463. HRESULT C_dxj_DirectPlayLobbyClientObject::GetProgs(GUID *guidApp)
  464. {
  465. // Enumerate all DirectPlay Local Progs
  466. HRESULT hr;
  467. DWORD dwSize=0;
  468. DWORD dwItems=0;
  469. __try {
  470. DPF(1,"-----Entering (DPlayLobbyClient) GetProgs call...\n");
  471. hr = m__dxj_DirectPlayLobbyClient->EnumLocalPrograms( guidApp, (BYTE*)m_ProgInfo, &dwSize, &dwItems, 0);
  472. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  473. return hr;
  474. m_ProgInfo = (DPL_APPLICATION_INFO*) new BYTE[dwSize];
  475. if( FAILED( hr = m__dxj_DirectPlayLobbyClient->EnumLocalPrograms( guidApp, (BYTE*)m_ProgInfo, &dwSize, &dwItems, 0) ) )
  476. return hr;
  477. m_dwAppCount = dwItems;
  478. }
  479. __except(EXCEPTION_EXECUTE_HANDLER)
  480. {
  481. return E_FAIL;
  482. }
  483. return S_OK;
  484. }
  485. HRESULT C_dxj_DirectPlayLobbyClientObject::UnRegisterMessageHandler()
  486. {
  487. DPF(1,"-----Entering (DPlayLobbyClient) UnregisterMessageHandler call...\n");
  488. m_fHandleEvents = FALSE;
  489. return S_OK;
  490. }
  491. HRESULT C_dxj_DirectPlayLobbyClientObject::GetConnectionSettings(long hLobbyClient, long lFlags, DPL_CONNECTION_SETTINGS_CDESC *ConnectionSettings)
  492. {
  493. DPL_CONNECTION_SETTINGS *desc = NULL;
  494. DWORD dwSize = 0;
  495. HRESULT hr = S_OK;
  496. WCHAR* wszAddress = NULL;
  497. WCHAR* wszDevice = NULL;
  498. DWORD dwNumChars = 0;
  499. __try {
  500. hr= m__dxj_DirectPlayLobbyClient->GetConnectionSettings((DPNHANDLE) hLobbyClient, NULL, &dwSize, (DWORD) lFlags);
  501. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  502. return hr;
  503. desc = (DPL_CONNECTION_SETTINGS*)new BYTE[dwSize];
  504. desc->dwSize = sizeof(DPL_CONNECTION_SETTINGS);
  505. hr= m__dxj_DirectPlayLobbyClient->GetConnectionSettings((DPNHANDLE) hLobbyClient, desc, &dwSize, (DWORD) lFlags);
  506. if( FAILED(hr))
  507. return hr;
  508. __try {
  509. hr = desc->pdp8HostAddress->GetURLW(NULL, &dwNumChars);
  510. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  511. return hr;
  512. wszAddress = (WCHAR*)_alloca(sizeof(WCHAR) * dwNumChars);
  513. if (FAILED (hr = desc->pdp8HostAddress->GetURLW(wszAddress,&dwNumChars) ) )
  514. return hr;
  515. ConnectionSettings->AddressSenderUrl = SysAllocString(wszAddress);
  516. }
  517. __except(EXCEPTION_EXECUTE_HANDLER)
  518. {
  519. // Just skip this part
  520. }
  521. __try {
  522. dwNumChars = 0;
  523. hr = ((IDirectPlay8Address*)*desc->ppdp8DeviceAddresses)->GetURLW(NULL, &dwNumChars);
  524. if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
  525. return hr;
  526. wszDevice = (WCHAR*)_alloca(sizeof(WCHAR) * dwNumChars);
  527. if (FAILED (hr = ((IDirectPlay8Address*)*desc->ppdp8DeviceAddresses)->GetURLW(wszDevice,&dwNumChars) ) )
  528. return hr;
  529. ConnectionSettings->AddressDeviceUrl = SysAllocString(wszDevice);
  530. }
  531. __except(EXCEPTION_EXECUTE_HANDLER)
  532. {
  533. // Just skip this part
  534. }
  535. GetVBConnSettings(desc, ConnectionSettings);
  536. }
  537. __except(EXCEPTION_EXECUTE_HANDLER)
  538. {
  539. return E_FAIL;
  540. }
  541. return S_OK;
  542. }
  543. HRESULT C_dxj_DirectPlayLobbyClientObject::SetConnectionSettings(long hTarget, long lFlags, DPL_CONNECTION_SETTINGS_CDESC *ConnectionSettings, I_dxj_DirectPlayAddress *HostAddress, I_dxj_DirectPlayAddress *Device)
  544. {
  545. DPL_CONNECTION_SETTINGS desc;
  546. HRESULT hr = S_OK;
  547. GUID guidApp;
  548. GUID guidInst;
  549. WCHAR wszSessionName[MAX_PATH];
  550. WCHAR wszPassword[MAX_PATH];
  551. __try {
  552. ZeroMemory(&desc, sizeof(DPL_CONNECTION_SETTINGS));
  553. desc.dwSize = sizeof(DPL_CONNECTION_SETTINGS);
  554. desc.dwFlags = ConnectionSettings->lFlags;
  555. HostAddress->InternalGetObject((IUnknown**)&desc.pdp8HostAddress);
  556. Device->InternalGetObject((IUnknown**)desc.ppdp8DeviceAddresses);
  557. ZeroMemory(&desc.dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
  558. // Set up our Desc
  559. desc.dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
  560. if (!IsEmptyString(ConnectionSettings->ApplicationDescription.SessionName))
  561. {
  562. wcscpy(wszSessionName,ConnectionSettings->ApplicationDescription.SessionName);
  563. desc.dpnAppDesc.pwszSessionName = wszSessionName;
  564. }
  565. if (!IsEmptyString(ConnectionSettings->ApplicationDescription.Password))
  566. {
  567. wcscpy(wszPassword,ConnectionSettings->ApplicationDescription.Password);
  568. desc.dpnAppDesc.pwszPassword = wszPassword;
  569. }
  570. desc.dpnAppDesc.dwFlags = ConnectionSettings->ApplicationDescription.lFlags;
  571. desc.dpnAppDesc.dwMaxPlayers = ConnectionSettings->ApplicationDescription.lMaxPlayers;
  572. desc.dpnAppDesc.dwCurrentPlayers = ConnectionSettings->ApplicationDescription.lCurrentPlayers;
  573. if (FAILED(hr = DPLAYBSTRtoGUID(&guidApp, ConnectionSettings->ApplicationDescription.guidApplication) ) )
  574. return hr;
  575. desc.dpnAppDesc.guidApplication = guidApp;
  576. if (FAILED(hr = DPLAYBSTRtoGUID(&guidInst, ConnectionSettings->ApplicationDescription.guidInstance) ) )
  577. return hr;
  578. desc.dpnAppDesc.guidInstance = guidInst;
  579. hr= m__dxj_DirectPlayLobbyClient->SetConnectionSettings((DPNHANDLE) hTarget, &desc, (DWORD) lFlags);
  580. if( FAILED(hr))
  581. return hr;
  582. }
  583. __except(EXCEPTION_EXECUTE_HANDLER)
  584. {
  585. return E_FAIL;
  586. }
  587. return S_OK;
  588. }
  589. HRESULT C_dxj_DirectPlayLobbyClientObject::GetVBConnSettings(DPL_CONNECTION_SETTINGS *OldCon, DPL_CONNECTION_SETTINGS_CDESC *NewCon)
  590. {
  591. IDirectPlay8Address *dpAdd = NULL;
  592. HRESULT hr;
  593. __try {
  594. NewCon->lSize = OldCon->dwSize;
  595. NewCon->lFlags = OldCon->dwFlags;
  596. NewCon->PlayerName = SysAllocString(OldCon->pwszPlayerName);
  597. ZeroMemory(&NewCon->ApplicationDescription, sizeof(DPN_APPLICATION_DESC_CDESC));
  598. // Set up our Desc
  599. NewCon->ApplicationDescription.lSize = OldCon->dpnAppDesc.dwSize;
  600. NewCon->ApplicationDescription.SessionName = SysAllocString(OldCon->dpnAppDesc.pwszSessionName);
  601. NewCon->ApplicationDescription.Password = SysAllocString(OldCon->dpnAppDesc.pwszPassword);
  602. NewCon->ApplicationDescription.lFlags = OldCon->dpnAppDesc.dwFlags;
  603. NewCon->ApplicationDescription.lMaxPlayers = OldCon->dpnAppDesc.dwMaxPlayers;
  604. NewCon->ApplicationDescription.lCurrentPlayers = OldCon->dpnAppDesc.dwCurrentPlayers;
  605. NewCon->ApplicationDescription.guidApplication = GUIDtoBSTR(&OldCon->dpnAppDesc.guidApplication);
  606. NewCon->ApplicationDescription.guidInstance = GUIDtoBSTR(&OldCon->dpnAppDesc.guidInstance);
  607. }
  608. __except(EXCEPTION_EXECUTE_HANDLER)
  609. {
  610. return E_FAIL;
  611. }
  612. return S_OK;
  613. }
  614. DWORD WINAPI CloseLobbyClientThreadProc(void* lpParam)
  615. {
  616. // User context for the message handler is a pointer to our class module.
  617. IDirectPlay8LobbyClient *lpPeer = (IDirectPlay8LobbyClient*)lpParam;
  618. DPF(1,"-----Entering (DPlayLobbiedApp) ClosePeerThreadProc call...\n");
  619. lpPeer->Close(0);
  620. DPF(1,"-----Leaving (DPlayLobbiedApp) ClosePeerThreadProc call ...\n");
  621. return 0;
  622. }