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.

1060 lines
23 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dplaylobby3obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // _dxj_DirectPlayLobbyObj.cp\p : Implementation of C_dxj_DirectPlayLobbyObject
  11. // DHF begin - entire file
  12. #include "stdafx.h"
  13. #include "Direct.h"
  14. #include "dms.h"
  15. #include "dplay.h"
  16. #include "dplobby.h"
  17. #include "dxglob7obj.h"
  18. #include "dPlayLobby3Obj.h"
  19. #include "dPlay4Obj.h"
  20. #include "DPAddressObj.h"
  21. #include "DPLConnectionObj.h"
  22. #include "DPEnumLocalApplications.h"
  23. //#include "dpEnumAddressObj.h"
  24. //#include "dpEnumAddressTypesObj.h"
  25. #include "dpmsgObj.h"
  26. #include "string.h"
  27. typedef HRESULT (__stdcall *DIRECTPLAYLOBBYCREATE)(LPGUID, LPDIRECTPLAYLOBBY *, IUnknown *, LPVOID, DWORD );
  28. extern DIRECTPLAYLOBBYCREATE pDirectPlayLobbyCreate;
  29. typedef HRESULT (__stdcall *DIRECTPLAYENUMERATE)( LPDPENUMDPCALLBACK, LPVOID );
  30. extern DIRECTPLAYENUMERATE pDirectPlayEnumerate;
  31. extern HRESULT BSTRtoPPGUID(LPGUID*,BSTR);
  32. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  33. extern BSTR GUIDtoBSTR(LPGUID);
  34. extern void *g_dxj_DirectPlay4;
  35. extern HINSTANCE g_hDPlay;
  36. BSTR DPLGUIDtoBSTR(LPGUID pGuid);
  37. HRESULT DPLBSTRtoGUID(LPGUID pGuid,BSTR str);
  38. C_dxj_DirectPlayLobby3Object::C_dxj_DirectPlayLobby3Object()
  39. {
  40. m__dxj_DirectPlayLobby3 = NULL;
  41. #pragma message("DirectPlayLobby3 should be in object list")
  42. }
  43. C_dxj_DirectPlayLobby3Object::~C_dxj_DirectPlayLobby3Object()
  44. {
  45. if(m__dxj_DirectPlayLobby3)
  46. {
  47. m__dxj_DirectPlayLobby3->Release();
  48. m__dxj_DirectPlayLobby3 = NULL;
  49. }
  50. }
  51. GETSET_OBJECT(_dxj_DirectPlayLobby3);
  52. //
  53. /*** I_dxj_DirectPlayLobby methods ***/
  54. //
  55. //////////////////////////////////////////////////////////////////////////
  56. STDMETHODIMP C_dxj_DirectPlayLobby3Object::connect(long flags, I_dxj_DirectPlay4 **val)
  57. {
  58. LPDIRECTPLAY2 dp=NULL;
  59. LPDIRECTPLAY4 dp4=NULL;
  60. HRESULT hr;
  61. hr= m__dxj_DirectPlayLobby3->Connect((DWORD) flags, &dp, NULL);
  62. if FAILED(hr) return hr;
  63. hr= dp->QueryInterface(IID_IDirectPlay4,(void**)&dp4);
  64. dp->Release();
  65. if FAILED(hr) return hr;
  66. INTERNAL_CREATE(_dxj_DirectPlay4, dp4, val)
  67. return hr;
  68. }
  69. //////////////////////////////////////////////////////////////////////////
  70. STDMETHODIMP C_dxj_DirectPlayLobby3Object::getConnectionSettings(
  71. /* [in] */ long AppID,
  72. /* [out]*/ I_dxj_DPLConnection **con){
  73. DWORD dataSize = 0;
  74. LPVOID data;
  75. HRESULT hr;
  76. if (!con) return E_INVALIDARG;
  77. hr= m__dxj_DirectPlayLobby3->GetConnectionSettings((DWORD)AppID, NULL, &dataSize);
  78. //fix for bug 23385
  79. if (hr!=DPERR_BUFFERTOOSMALL) return hr;
  80. *con=NULL;
  81. //Andrewke-
  82. //we now pass pack null if there are no connection settings.
  83. //will this ever happen?
  84. if (dataSize==0) return S_OK;
  85. data = alloca(dataSize);
  86. hr = m__dxj_DirectPlayLobby3->GetConnectionSettings((DWORD)AppID, (LPVOID)data, &dataSize);
  87. if FAILED(hr){
  88. return E_OUTOFMEMORY;
  89. }
  90. I_dxj_DPLConnection *dplConnection=NULL;
  91. INTERNAL_CREATE_STRUCT(_dxj_DPLConnection,(&dplConnection));
  92. if (dplConnection==NULL){
  93. return E_OUTOFMEMORY;
  94. }
  95. hr=dplConnection->setConnectionStruct((long)PtrToLong(data)); //NOTE SUNDOWN issue
  96. if FAILED(hr){
  97. return hr;
  98. }
  99. *con=dplConnection;
  100. return S_OK;
  101. }
  102. //////////////////////////////////////////////////////////////////////////
  103. STDMETHODIMP C_dxj_DirectPlayLobby3Object::receiveLobbyMessage(
  104. /* [in] */ long appID,
  105. /* [out] */ long *messageFlags,
  106. /* [out] */ I_dxj_DirectPlayMessage **msg)
  107. {
  108. HRESULT hr;
  109. DWORD dwSize=0;
  110. void *pData=NULL;
  111. BOOL fCont=TRUE;
  112. if (!msg) return E_INVALIDARG;
  113. if (!messageFlags) return E_INVALIDARG;
  114. hr= m__dxj_DirectPlayLobby3->ReceiveLobbyMessage (0,
  115. appID,
  116. (DWORD*)messageFlags,
  117. (void*)NULL,
  118. (LPDWORD)&dwSize);
  119. if (hr == DPERR_NOMESSAGES ) {
  120. *msg=NULL;
  121. return S_OK;
  122. }
  123. if (hr!=DPERR_BUFFERTOOSMALL) return hr;
  124. hr=C_dxj_DirectPlayMessageObject::create((DWORD)0,dwSize,&pData,msg);
  125. if FAILED(hr) return hr;
  126. hr= m__dxj_DirectPlayLobby3->ReceiveLobbyMessage (0,
  127. appID,
  128. (DWORD*)messageFlags,
  129. (void*)pData,
  130. (LPDWORD)&dwSize);
  131. if FAILED(hr) {
  132. if (*msg) (*msg)->Release();
  133. *msg=NULL;
  134. return hr;
  135. }
  136. return hr;
  137. }
  138. //////////////////////////////////////////////////////////////////////////
  139. STDMETHODIMP C_dxj_DirectPlayLobby3Object::receiveLobbyMessageSize(
  140. /* [in] */ long appID,
  141. /* [out] */ long *messageFlags,
  142. /* [out] */ long __RPC_FAR *dataSize)
  143. {
  144. *dataSize = 0;
  145. HRESULT hr = m__dxj_DirectPlayLobby3->ReceiveLobbyMessage (0,
  146. appID,
  147. (DWORD*)messageFlags,
  148. NULL,
  149. (LPDWORD)dataSize);
  150. if (hr==DPERR_BUFFERTOOSMALL) hr=S_OK;
  151. return hr;
  152. }
  153. //////////////////////////////////////////////////////////////////////////
  154. // Launch a DirectPlay application.
  155. //////////////////////////////////////////////////////////////////////////
  156. STDMETHODIMP C_dxj_DirectPlayLobby3Object::runApplication(
  157. I_dxj_DPLConnection *conn,
  158. long hReceiveEvent ,
  159. long *appId
  160. )
  161. {
  162. if (!appId) return E_INVALIDARG;
  163. if (!conn) return E_INVALIDARG;
  164. void *lpConnection=NULL;
  165. HRESULT hr;
  166. *appId=0;
  167. hr=conn->getConnectionStruct((long*)&lpConnection);
  168. if FAILED(hr) return hr;
  169. hr = m__dxj_DirectPlayLobby3->RunApplication (0,
  170. (DWORD*)appId,
  171. (DPLCONNECTION*)lpConnection,
  172. (void*)hReceiveEvent);
  173. return hr;
  174. }
  175. /////////////////////////////////////////////////////////////////////////////
  176. STDMETHODIMP C_dxj_DirectPlayLobby3Object::sendLobbyMessage(
  177. /* [in] */ long flags,
  178. /* [in] */ long appID,
  179. /* [in] */ I_dxj_DirectPlayMessage *msg)
  180. {
  181. //if (!ISSAFEARRAY1D(ppData,(DWORD)dataSize)) return E_INVALIDARG;
  182. HRESULT hr;
  183. if (!msg) return E_INVALIDARG;
  184. void *pData=NULL;
  185. DWORD dataSize=0;
  186. msg->AddRef();
  187. msg->getPointer((long*)&pData);
  188. msg->getMessageSize((long*)&dataSize);
  189. __try {
  190. hr = m__dxj_DirectPlayLobby3->SendLobbyMessage ((DWORD)flags,
  191. (DWORD)appID,
  192. pData,
  193. (DWORD)dataSize);
  194. }
  195. __except(1,1){
  196. msg->Release();
  197. return E_INVALIDARG;
  198. }
  199. msg->Release();
  200. return hr;
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. STDMETHODIMP C_dxj_DirectPlayLobby3Object::setConnectionSettings ( long appID, I_dxj_DPLConnection *con)
  204. {
  205. void *lpConnection=NULL;
  206. HRESULT hr;
  207. if (!con) return E_INVALIDARG;
  208. hr=con->getConnectionStruct((long*)&lpConnection);
  209. if FAILED(hr) return hr;
  210. hr = m__dxj_DirectPlayLobby3->SetConnectionSettings (0,
  211. (DWORD)appID,
  212. (DPLCONNECTION*)lpConnection);
  213. return hr;
  214. }
  215. //////////////////////////////////////////////////////////////////////////
  216. STDMETHODIMP C_dxj_DirectPlayLobby3Object::setLobbyMessageEvent(
  217. /* [in] */ long appId,
  218. /* [in] */ long hReceiveEvent)
  219. {
  220. HRESULT hr = m__dxj_DirectPlayLobby3->SetLobbyMessageEvent(0, (long)appId, (HANDLE)hReceiveEvent);
  221. return hr;
  222. }
  223. STDMETHODIMP C_dxj_DirectPlayLobby3Object::getDPEnumLocalApplications(
  224. ///* [in] */ long flags,
  225. /* [retval][out] */ I_dxj_DPEnumLocalApplications __RPC_FAR *__RPC_FAR *retVal)
  226. {
  227. HRESULT hr;
  228. hr=C_dxj_DPEnumLocalApplicationsObject::create(m__dxj_DirectPlayLobby3,0,retVal);
  229. return hr;
  230. }
  231. STDMETHODIMP C_dxj_DirectPlayLobby3Object::waitForConnectionSettings(
  232. /* [in] */ long flags)
  233. {
  234. HRESULT hr = m__dxj_DirectPlayLobby3->WaitForConnectionSettings((DWORD)flags);
  235. return hr;
  236. }
  237. STDMETHODIMP C_dxj_DirectPlayLobby3Object::unregisterApplication(// long flags,
  238. BSTR guid)
  239. {
  240. GUID g;
  241. HRESULT hr;
  242. hr=DPLBSTRtoGUID(&g,guid);
  243. if FAILED(hr) return E_INVALIDARG;
  244. hr =m__dxj_DirectPlayLobby3->UnregisterApplication((DWORD) 0, g);
  245. return hr;
  246. }
  247. STDMETHODIMP C_dxj_DirectPlayLobby3Object::registerApplication(// long flags,
  248. DpApplicationDesc2 *appDesc)
  249. {
  250. HRESULT hr;
  251. DPAPPLICATIONDESC2 desc;
  252. if (!appDesc->strGuid) return E_INVALIDARG;
  253. ZeroMemory(&desc,sizeof(DPAPPLICATIONDESC2));
  254. desc.dwSize=sizeof(DPAPPLICATIONDESC2);
  255. desc.dwFlags=(DWORD)appDesc->lFlags;
  256. desc.lpszApplicationName=appDesc->strApplicationName;
  257. desc.lpszFilename=appDesc->strFilename;
  258. desc.lpszCommandLine=appDesc->strCommandLine;
  259. desc.lpszPath=appDesc->strPath;
  260. desc.lpszCurrentDirectory=appDesc->strCurrentDirectory;
  261. desc.lpszDescriptionW=appDesc->strDescription;
  262. desc.lpszAppLauncherName=appDesc->strAppLauncherName;
  263. hr=DPLBSTRtoGUID(&desc.guidApplication,appDesc->strGuid);
  264. if FAILED(hr) return E_INVALIDARG;
  265. hr =m__dxj_DirectPlayLobby3->RegisterApplication((DWORD) 0, &desc);
  266. return hr;
  267. }
  268. STDMETHODIMP C_dxj_DirectPlayLobby3Object::createConnectionData( I_dxj_DPLConnection __RPC_FAR *__RPC_FAR *ret)
  269. {
  270. INTERNAL_CREATE_STRUCT(_dxj_DPLConnection,ret);
  271. return S_OK;
  272. }
  273. STDMETHODIMP C_dxj_DirectPlayLobby3Object::createMessage( I_dxj_DirectPlayMessage __RPC_FAR *__RPC_FAR *ret)
  274. {
  275. HRESULT hr;
  276. hr= C_dxj_DirectPlayMessageObject::create(1,0,NULL,ret);
  277. return hr;
  278. }
  279. //CONSIDER - why pass int - more appopriate to pass in short
  280. STDMETHODIMP C_dxj_DirectPlayLobby3Object::createINetAddress(
  281. /* [in] */ BSTR addr,
  282. /* [in] */ int port,
  283. /* [retval][out] */ I_dxj_DPAddress __RPC_FAR *__RPC_FAR *ret)
  284. {
  285. DPCOMPOUNDADDRESSELEMENT elem[3];
  286. DWORD dwSize=0;
  287. LPVOID pAddress=NULL;
  288. HRESULT hr;
  289. I_dxj_DPAddress *pDPAddress= NULL;
  290. WORD wport=(WORD)port;
  291. DWORD dwElements=2;
  292. if (!addr) return E_INVALIDARG;
  293. elem[0].guidDataType=DPAID_ServiceProvider;
  294. elem[0].dwDataSize =sizeof(GUID);
  295. elem[0].lpData = (void*) &DPSPGUID_TCPIP;
  296. elem[1].guidDataType=DPAID_INetW;
  297. elem[1].dwDataSize =SysStringByteLen(addr)+sizeof(WCHAR);
  298. elem[1].lpData = (void*) addr;
  299. elem[2].guidDataType=DPAID_INetPort;
  300. elem[2].dwDataSize =sizeof(WORD);
  301. elem[2].lpData = &wport;
  302. if (port) dwElements=3;
  303. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,dwElements,NULL,&dwSize);
  304. if (hr!=DPERR_BUFFERTOOSMALL) return hr;
  305. pAddress=malloc(dwSize);
  306. if (!pAddress) return E_OUTOFMEMORY;
  307. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,dwElements,pAddress,&dwSize);
  308. if FAILED(hr) {
  309. free(pAddress);
  310. return hr;
  311. }
  312. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,(&pDPAddress));
  313. if (pDPAddress==NULL) {
  314. free(pAddress);
  315. return E_OUTOFMEMORY;
  316. }
  317. pDPAddress->setAddress((long)PtrToLong(pAddress),(long)dwSize); //NOTE SUNDOWN issue need to use PtrToLong
  318. free(pAddress);
  319. *ret=pDPAddress;
  320. return hr;
  321. }
  322. STDMETHODIMP C_dxj_DirectPlayLobby3Object::createComPortAddress(
  323. /* [in] */ long port,
  324. /* [in] */ long baudRate,
  325. /* [in] */ long stopBits,
  326. /* [in] */ long parity,
  327. /* [in] */ long flowcontrol,
  328. /* [retval][out] */ I_dxj_DPAddress __RPC_FAR *__RPC_FAR *ret)
  329. {
  330. DPCOMPORTADDRESS cpa;
  331. cpa.dwBaudRate =(DWORD)baudRate;
  332. cpa.dwComPort =(DWORD)port;
  333. cpa.dwFlowControl =(DWORD)flowcontrol;
  334. cpa.dwStopBits =(DWORD)stopBits;
  335. cpa.dwParity =(DWORD)parity;
  336. DPCOMPOUNDADDRESSELEMENT elem[2];
  337. DWORD dwSize=0;
  338. LPVOID pAddress=NULL;
  339. HRESULT hr;
  340. I_dxj_DPAddress *pDPAddress= NULL;
  341. elem[0].guidDataType=DPAID_ServiceProvider;
  342. elem[0].dwDataSize =sizeof(GUID);
  343. elem[0].lpData = (void*) &DPSPGUID_SERIAL;
  344. elem[1].guidDataType=DPAID_ComPort;
  345. elem[1].dwDataSize =sizeof(DPCOMPORTADDRESS);
  346. elem[1].lpData = (void*) &cpa;
  347. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,2,NULL,&dwSize);
  348. if (hr!=DPERR_BUFFERTOOSMALL) return hr;
  349. pAddress=malloc(dwSize);
  350. if (!pAddress) return E_OUTOFMEMORY;
  351. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,2,pAddress,&dwSize);
  352. if FAILED(hr) {
  353. free(pAddress);
  354. return hr;
  355. }
  356. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,(&pDPAddress));
  357. if (pDPAddress==NULL) {
  358. free(pAddress);
  359. return E_OUTOFMEMORY;
  360. }
  361. pDPAddress->setAddress((long)PtrToLong(pAddress),(long)dwSize); //NOTE SUNDOWN issue
  362. free(pAddress);
  363. *ret=pDPAddress;
  364. return hr;
  365. }
  366. STDMETHODIMP C_dxj_DirectPlayLobby3Object::createLobbyProviderAddress(
  367. /* [in] */ BSTR guid,
  368. /* [retval][out] */ I_dxj_DPAddress __RPC_FAR *__RPC_FAR *ret)
  369. {
  370. DPCOMPOUNDADDRESSELEMENT elem[2];
  371. DWORD dwSize=0;
  372. LPVOID pAddress=NULL;
  373. HRESULT hr;
  374. I_dxj_DPAddress *pDPAddress= NULL;
  375. GUID lobbyGuid;
  376. if (!guid) return E_INVALIDARG;
  377. hr=DPLBSTRtoGUID(&lobbyGuid,guid);
  378. if FAILED(hr) return E_INVALIDARG;
  379. elem[0].guidDataType=DPAID_LobbyProvider;
  380. elem[0].dwDataSize =sizeof(GUID);
  381. elem[0].lpData = (void*) &lobbyGuid;
  382. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,1,NULL,&dwSize);
  383. if (hr!=DPERR_BUFFERTOOSMALL) return hr;
  384. pAddress=malloc(dwSize);
  385. if (!pAddress) return E_OUTOFMEMORY;
  386. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,1,pAddress,&dwSize);
  387. if FAILED(hr) {
  388. free(pAddress);
  389. return hr;
  390. }
  391. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,(&pDPAddress));
  392. if (pDPAddress==NULL) {
  393. free(pAddress);
  394. return E_OUTOFMEMORY;
  395. }
  396. pDPAddress->setAddress((long)PtrToLong(pAddress),(long)dwSize); //NOTE SUNDOWN
  397. free(pAddress);
  398. *ret=pDPAddress;
  399. return hr;
  400. }
  401. STDMETHODIMP C_dxj_DirectPlayLobby3Object::createServiceProviderAddress(
  402. /* [in] */ BSTR guid,
  403. /* [retval][out] */ I_dxj_DPAddress __RPC_FAR *__RPC_FAR *ret)
  404. {
  405. DPCOMPOUNDADDRESSELEMENT elem[1];
  406. DWORD dwSize=0;
  407. LPVOID pAddress=NULL;
  408. HRESULT hr;
  409. I_dxj_DPAddress *pDPAddress= NULL;
  410. GUID SPGuid;
  411. if (!guid) return E_INVALIDARG;
  412. hr=DPLBSTRtoGUID(&SPGuid,guid);
  413. if FAILED(hr) return E_INVALIDARG;
  414. elem[0].guidDataType=DPAID_ServiceProvider;
  415. elem[0].dwDataSize =sizeof(GUID);
  416. elem[0].lpData = (void*) &SPGuid;
  417. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,1,NULL,&dwSize);
  418. if (hr!=DPERR_BUFFERTOOSMALL) return hr;
  419. pAddress=malloc(dwSize);
  420. if (!pAddress) return E_OUTOFMEMORY;
  421. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,1,pAddress,&dwSize);
  422. if FAILED(hr) {
  423. free(pAddress);
  424. return hr;
  425. }
  426. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,(&pDPAddress));
  427. if (pDPAddress==NULL) {
  428. free(pAddress);
  429. return E_OUTOFMEMORY;
  430. }
  431. pDPAddress->setAddress((long)PtrToLong(pAddress),(long)dwSize); //NOTE SUNDOWN
  432. free(pAddress);
  433. *ret=pDPAddress;
  434. return hr;
  435. }
  436. STDMETHODIMP C_dxj_DirectPlayLobby3Object::createModemAddress(
  437. /* [in] */ BSTR modem,
  438. /* [in] */ BSTR phone,
  439. /* [retval][out] */ I_dxj_DPAddress __RPC_FAR *__RPC_FAR *ret)
  440. {
  441. DPCOMPOUNDADDRESSELEMENT elem[3];
  442. DWORD dwSize=0;
  443. DWORD i =1;
  444. LPVOID pAddress=NULL;
  445. HRESULT hr;
  446. I_dxj_DPAddress *pDPAddress= NULL;
  447. if (!phone) return E_INVALIDARG;
  448. if (!modem) return E_INVALIDARG;
  449. elem[0].guidDataType=DPAID_ServiceProvider;
  450. elem[0].dwDataSize =sizeof(GUID);
  451. elem[0].lpData = (void*) &DPSPGUID_MODEM;
  452. if (modem[0]!=0) {
  453. elem[i].guidDataType=DPAID_ModemW;
  454. elem[i].dwDataSize =SysStringByteLen(modem)+sizeof(WCHAR);
  455. elem[i].lpData = (void*) modem;
  456. i++;
  457. }
  458. if (phone[0]!=0) {
  459. elem[i].guidDataType=DPAID_PhoneW;
  460. elem[i].dwDataSize =SysStringByteLen(phone)+sizeof(WCHAR);
  461. elem[i].lpData = (void*) phone;
  462. i++;
  463. }
  464. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,i,NULL,&dwSize);
  465. if (hr!=DPERR_BUFFERTOOSMALL) return hr;
  466. pAddress=malloc(dwSize);
  467. if (!pAddress) return E_OUTOFMEMORY;
  468. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,i,pAddress,&dwSize);
  469. if FAILED(hr) {
  470. free(pAddress);
  471. return hr;
  472. }
  473. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,(&pDPAddress));
  474. if (pDPAddress==NULL) {
  475. free(pAddress);
  476. return E_OUTOFMEMORY;
  477. }
  478. pDPAddress->setAddress((long)PtrToLong(pAddress),(long)dwSize); //NOTE SUNDOWN
  479. free(pAddress);
  480. *ret=pDPAddress;
  481. return hr;
  482. }
  483. STDMETHODIMP C_dxj_DirectPlayLobby3Object::createIPXAddress(
  484. /* [retval][out] */ I_dxj_DPAddress __RPC_FAR *__RPC_FAR *ret)
  485. {
  486. DPCOMPOUNDADDRESSELEMENT elem[1];
  487. DWORD dwSize=0;
  488. LPVOID pAddress=NULL;
  489. HRESULT hr;
  490. I_dxj_DPAddress *pDPAddress= NULL;
  491. GUID SPGuid=DPSPGUID_IPX;
  492. elem[0].guidDataType=DPAID_ServiceProvider;
  493. elem[0].dwDataSize =sizeof(GUID);
  494. elem[0].lpData = (void*) &SPGuid;
  495. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,1,NULL,&dwSize);
  496. if (hr!=DPERR_BUFFERTOOSMALL) return hr;
  497. pAddress=malloc(dwSize);
  498. if (!pAddress) return E_OUTOFMEMORY;
  499. hr=m__dxj_DirectPlayLobby3->CreateCompoundAddress(elem,1,pAddress,&dwSize);
  500. if FAILED(hr) {
  501. free(pAddress);
  502. return hr;
  503. }
  504. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,(&pDPAddress));
  505. if (pDPAddress==NULL) {
  506. free(pAddress);
  507. return E_OUTOFMEMORY;
  508. }
  509. pDPAddress->setAddress((long)PtrToLong(pAddress),(long)dwSize); //NOTE SUNDOWN
  510. free(pAddress);
  511. *ret=pDPAddress;
  512. return hr;
  513. }
  514. STDMETHODIMP C_dxj_DirectPlayLobby3Object::createCustomAddress(
  515. /* [in] */ long size,
  516. /* [in] */ void __RPC_FAR *data,
  517. /* [retval][out] */ I_dxj_DPAddress __RPC_FAR *__RPC_FAR *ret)
  518. {
  519. return E_NOTIMPL;
  520. }
  521. STDMETHODIMP C_dxj_DirectPlayLobby3Object::getModemName(
  522. /* [in] */ long index,
  523. /* [retval][out] */ BSTR *name)
  524. {
  525. USES_CONVERSION;
  526. LPDIRECTPLAY4 dp=NULL;
  527. LPDIRECTPLAY lpDP=NULL;
  528. GUID guid=DPSPGUID_MODEM;
  529. HRESULT hr;
  530. DIRECTPLAYCREATE pDirectPlayCreate = NULL;
  531. DWORD dwSize=0;
  532. DWORD dwAt=0;
  533. void *pData=NULL;
  534. LPWSTR pszwName=NULL;
  535. char *szLast=NULL;
  536. DWORD dwCount;
  537. DWORD i;
  538. BOOL bZero;
  539. pDirectPlayCreate=(DIRECTPLAYCREATE)GetProcAddress( g_hDPlay, "DirectPlayCreate" );
  540. if (pDirectPlayCreate == NULL ) return E_NOINTERFACE;
  541. // create a DirectPlay1 interface
  542. hr = (pDirectPlayCreate)(&guid, &lpDP, NULL);
  543. if FAILED(hr) goto cleanup;
  544. // now get Dplay4 interface
  545. hr = lpDP->QueryInterface(IID_IDirectPlay4,(LPVOID *)&dp);
  546. lpDP->Release(); lpDP=NULL;
  547. if FAILED(hr) goto cleanup;
  548. hr=dp->GetPlayerAddress(0,NULL,&dwSize);
  549. if (dwSize<=0) {
  550. hr=E_INVALIDARG;
  551. goto cleanup;
  552. }
  553. pData=malloc(dwSize);
  554. if (!pData){
  555. hr= E_OUTOFMEMORY;
  556. goto cleanup;
  557. }
  558. hr=dp->GetPlayerAddress(0,pData,&dwSize);
  559. if FAILED(hr) goto cleanup;
  560. if (dwSize<=80) {
  561. hr=E_INVALIDARG;
  562. goto cleanup;
  563. }
  564. //Get String count
  565. bZero=FALSE;
  566. dwCount=0;
  567. for( i=80;i<dwSize;i++){
  568. if (((char*)pData)[i]==0){
  569. if (bZero) break;
  570. dwCount++;
  571. bZero=TRUE;
  572. }
  573. else {
  574. bZero=FALSE;
  575. }
  576. }
  577. if (((DWORD)index > dwCount) || (index <=0)){
  578. hr=E_INVALIDARG;
  579. goto cleanup;
  580. }
  581. szLast=& (((char*)pData)[80]);
  582. dwAt=0;
  583. for ( i=80;i<dwSize;i++){
  584. if (((char*)pData)[i]==0){
  585. if ((DWORD)(index-1)==dwAt) break;
  586. dwAt++;
  587. szLast=&( ( (char*)pData)[i+1]);
  588. }
  589. }
  590. if (i>dwSize) {
  591. hr=E_INVALIDARG;
  592. goto cleanup;
  593. }
  594. pszwName = T2W(szLast);
  595. *name=SysAllocString(pszwName);
  596. cleanup:
  597. if (pData) free(pData);
  598. if (dp) dp->Release();
  599. return hr;
  600. }
  601. STDMETHODIMP C_dxj_DirectPlayLobby3Object::getModemCount(
  602. /* [retval][out] */ long __RPC_FAR *count)
  603. {
  604. LPDIRECTPLAY4 dp=NULL;
  605. LPDIRECTPLAY lpDP=NULL;
  606. GUID guid=DPSPGUID_MODEM;
  607. HRESULT hr;
  608. DIRECTPLAYCREATE pDirectPlayCreate = NULL;
  609. DWORD dwSize=0;
  610. void *pData=NULL;
  611. DWORD dwCount;
  612. DWORD i;
  613. BOOL bZero;
  614. if (!count) return E_INVALIDARG;
  615. pDirectPlayCreate=(DIRECTPLAYCREATE)GetProcAddress( g_hDPlay, "DirectPlayCreate" );
  616. if (pDirectPlayCreate == NULL ) return E_NOINTERFACE;
  617. // create a DirectPlay1 interface
  618. hr = (pDirectPlayCreate)(&guid, &lpDP, NULL);
  619. if (hr==DPERR_UNAVAILABLE) {
  620. hr = S_OK;
  621. *count=0;
  622. goto cleanup;
  623. }
  624. if FAILED(hr) goto cleanup;
  625. // now get Dplay4 interface
  626. hr = lpDP->QueryInterface(IID_IDirectPlay4,(LPVOID *)&dp);
  627. lpDP->Release(); lpDP=NULL;
  628. if FAILED(hr) goto cleanup;
  629. hr=dp->GetPlayerAddress(0,NULL,&dwSize);
  630. if (dwSize<=0) {
  631. hr=E_INVALIDARG;
  632. goto cleanup;
  633. }
  634. pData=malloc(dwSize);
  635. if (!pData){
  636. hr= E_OUTOFMEMORY;
  637. goto cleanup;
  638. }
  639. hr=dp->GetPlayerAddress(0,pData,&dwSize);
  640. if (hr==DPERR_UNAVAILABLE) {
  641. hr = S_OK;
  642. *count=0;
  643. goto cleanup;
  644. }
  645. if FAILED(hr) goto cleanup;
  646. if (dwSize<=80) {
  647. hr=E_INVALIDARG;
  648. goto cleanup;
  649. }
  650. //Get String count
  651. bZero=FALSE;
  652. dwCount=0;
  653. for( i=80;i<dwSize;i++){
  654. if (((char*)pData)[i]==0){
  655. if (bZero) break;
  656. dwCount++;
  657. bZero=TRUE;
  658. }
  659. else {
  660. bZero=FALSE;
  661. }
  662. }
  663. *count=(long)dwCount;
  664. cleanup:
  665. if (pData) free(pData);
  666. if (dp) dp->Release();
  667. return hr;
  668. }
  669. #define GUIDS_EQUAL(g2,g) (\
  670. (g.Data1==g2->Data1) && \
  671. (g.Data2==g2->Data2) && \
  672. (g.Data3==g2->Data3) && \
  673. (g.Data4[0]==g2->Data4[0]) && \
  674. (g.Data4[1]==g2->Data4[1]) && \
  675. (g.Data4[2]==g2->Data4[2]) && \
  676. (g.Data4[3]==g2->Data4[3]) && \
  677. (g.Data4[4]==g2->Data4[4]) && \
  678. (g.Data4[5]==g2->Data4[5]) && \
  679. (g.Data4[6]==g2->Data4[6]) && \
  680. (g.Data4[7]==g2->Data4[7]) )
  681. HRESULT DPLBSTRtoGUID(LPGUID pGuid,BSTR str)
  682. {
  683. HRESULT hr;
  684. if( 0==_wcsicmp(str,L"dpaid_comport")){
  685. memcpy(pGuid,&DPAID_ComPort,sizeof(GUID));
  686. }
  687. else if( 0==_wcsicmp(str,L"dpaid_inet")){
  688. memcpy(pGuid,&DPAID_INet,sizeof(GUID));
  689. }
  690. else if( 0==_wcsicmp(str,L"dpaid_inetport")){
  691. memcpy(pGuid,&DPAID_INetPort,sizeof(GUID));
  692. }
  693. else if( 0==_wcsicmp(str,L"dpaid_lobbyprovider")){
  694. memcpy(pGuid,&DPAID_LobbyProvider,sizeof(GUID));
  695. }
  696. else if( 0==_wcsicmp(str,L"dpaid_modem")){
  697. memcpy(pGuid,&DPAID_Modem,sizeof(GUID));
  698. }
  699. else if( 0==_wcsicmp(str,L"dpaid_phone")){
  700. memcpy(pGuid,&DPAID_Phone,sizeof(GUID));
  701. }
  702. else if( 0==_wcsicmp(str,L"dpaid_serviceprovider")){
  703. memcpy(pGuid,&DPAID_ServiceProvider,sizeof(GUID));
  704. }
  705. else if( 0==_wcsicmp(str,L"dpaid_totalsize")){
  706. memcpy(pGuid,&DPAID_TotalSize,sizeof(GUID));
  707. }
  708. else if( 0==_wcsicmp(str,L"dpspguid_modem")){
  709. memcpy(pGuid,&DPSPGUID_MODEM,sizeof(GUID));
  710. }
  711. else if( 0==_wcsicmp(str,L"dpspguid_ipx")){
  712. memcpy(pGuid,&DPSPGUID_IPX,sizeof(GUID));
  713. }
  714. else if( 0==_wcsicmp(str,L"dpspguid_tcpip")){
  715. memcpy(pGuid,&DPSPGUID_TCPIP,sizeof(GUID));
  716. }
  717. else if( 0==_wcsicmp(str,L"dpspguid_serial")){
  718. memcpy(pGuid,&DPSPGUID_SERIAL,sizeof(GUID));
  719. }
  720. else {
  721. hr=BSTRtoGUID(pGuid,str);
  722. return hr;
  723. }
  724. return S_OK;
  725. }
  726. HRESULT DPLBSTRtoPPGUID(LPGUID *ppGuid,BSTR str)
  727. {
  728. if ((!str) || (str[0]==0)){
  729. ppGuid=NULL;
  730. return S_OK;
  731. }
  732. return DPLBSTRtoGUID(*ppGuid,str);
  733. }
  734. BSTR DPLGUIDtoBSTR(LPGUID pGuid)
  735. {
  736. WCHAR *pOut=NULL;
  737. if( GUIDS_EQUAL(pGuid,DPAID_ComPort)){
  738. pOut=L"DPAID_ComPort";
  739. }
  740. else if( GUIDS_EQUAL(pGuid,DPAID_INet)){
  741. pOut=L"DPAID_INet";
  742. }
  743. else if( GUIDS_EQUAL(pGuid,DPAID_INetPort)){
  744. pOut=L"DPAID_INetPort";
  745. }
  746. else if( GUIDS_EQUAL(pGuid,DPAID_LobbyProvider)){
  747. pOut=L"DPAID_LobbyProvider";
  748. }
  749. else if( GUIDS_EQUAL(pGuid,DPAID_Modem)){
  750. pOut=L"DPAID_Modem";
  751. }
  752. else if( GUIDS_EQUAL(pGuid,DPAID_Phone)){
  753. pOut=L"DPAID_Phone";
  754. }
  755. else if( GUIDS_EQUAL(pGuid,DPAID_ServiceProvider)){
  756. pOut=L"DPAID_ServiceProvider";
  757. }
  758. else if( GUIDS_EQUAL(pGuid,DPAID_TotalSize)){
  759. pOut=L"DPAID_TotalSize";
  760. }
  761. else if( GUIDS_EQUAL(pGuid,DPSPGUID_MODEM)){
  762. pOut=L"DPSPGUID_MODEM";
  763. }
  764. else if( GUIDS_EQUAL(pGuid,DPSPGUID_IPX)){
  765. pOut=L"DPSPGUID_IPX";
  766. }
  767. else if( GUIDS_EQUAL(pGuid,DPSPGUID_TCPIP)){
  768. pOut=L"DPSPGUID_TCPIP";
  769. }
  770. else if( GUIDS_EQUAL(pGuid,DPSPGUID_SERIAL)){
  771. pOut=L"DPSPGUID_SERIAL";
  772. }
  773. if (pOut) {
  774. return SysAllocString(pOut);
  775. }
  776. else {
  777. return GUIDtoBSTR(pGuid);
  778. }
  779. }