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.

496 lines
12 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1996-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dplobbya.c
  6. * Content: ANSI Methods for IDirectPlayLobby
  7. *
  8. * History:
  9. * Date By Reason
  10. * ======= ======= ======
  11. * 5/24/96 myronth Created it
  12. * 9/09/96 kipo Pass UNICODE IDirectPlayLobby interface to
  13. * DPL_Connect() instead of ANSI interface. Bug #3790.
  14. * 10/23/96 myronth Added client/server methods
  15. * 12/12/96 myronth Fixed DPLCONNECTION validation
  16. * 2/12/97 myronth Mass DX5 changes
  17. * 2/26/97 myronth #ifdef'd out DPASYNCDATA stuff (removed dependency)
  18. * 5/8/97 myronth Get/SetGroupConnectionSettings, removed dead code
  19. * 9/29/97 myronth Fixed DPLCONNECTION package size bug (#12475)
  20. * 11/5/97 myronth Fixed locking macro
  21. * 11/13/97 myronth Added stop async check for asynchronous Connect (#12541)
  22. * 12/2/97 myronth Added DPL_A_RegisterApplication
  23. * 12/3/97 myronth Changed DPCONNECT flag to DPCONNECT_RETURNSTATUS (#15451)
  24. * 6/25/98 a-peterz Added DPL_A_ConnectEx
  25. ***************************************************************************/
  26. #include "dplobpr.h"
  27. //--------------------------------------------------------------------------
  28. //
  29. // Functions
  30. //
  31. //--------------------------------------------------------------------------
  32. #undef DPF_MODNAME
  33. #define DPF_MODNAME "DPL_A_Connect"
  34. HRESULT DPLAPI DPL_A_Connect(LPDIRECTPLAYLOBBY lpDPL, DWORD dwFlags,
  35. LPDIRECTPLAY2 * lplpDP2A, IUnknown FAR * lpUnk)
  36. {
  37. HRESULT hr;
  38. LPDIRECTPLAY2 lpDP2;
  39. LPDIRECTPLAYLOBBY lpDPLW;
  40. DPF(7, "Entering DPL_A_Connect");
  41. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x, 0x%08x",
  42. lpDPL, dwFlags, lplpDP2A, lpUnk);
  43. ENTER_DPLOBBY();
  44. TRY
  45. {
  46. if( !VALID_WRITE_PTR( lplpDP2A, sizeof(LPDIRECTPLAY2 *) ) )
  47. {
  48. LEAVE_DPLOBBY();
  49. return DPERR_INVALIDPARAMS;
  50. }
  51. }
  52. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  53. {
  54. LEAVE_DPLOBBY();
  55. DPF_ERR( "Exception encountered validating parameters" );
  56. return DPERR_INVALIDPARAMS;
  57. }
  58. LEAVE_DPLOBBY();
  59. // QueryInterface for the UNICODE DirectPlayLobby interface
  60. hr = lpDPL->lpVtbl->QueryInterface(lpDPL, &IID_IDirectPlayLobby, &lpDPLW);
  61. if(FAILED(hr))
  62. {
  63. DPF_ERR("Unable to QueryInterface for the UNICODE DirectPlayLobby interface");
  64. return (hr);
  65. }
  66. // Use the UNICODE IDirectPlayLobby interface (fixes bug #3790)
  67. hr = DPL_Connect(lpDPLW, dwFlags, &lpDP2, lpUnk);
  68. // release UNICODE IDirectPlayLobby interface
  69. lpDPLW->lpVtbl->Release(lpDPLW);
  70. lpDPLW = NULL;
  71. if(SUCCEEDED(hr))
  72. {
  73. ENTER_DPLOBBY();
  74. // QueryInterface for the ANSI interface
  75. hr = lpDP2->lpVtbl->QueryInterface(lpDP2, &IID_IDirectPlay2A, lplpDP2A);
  76. if(FAILED(hr))
  77. {
  78. DPF_ERR("Unable to QueryInterface for the ANSI DirectPlay interface");
  79. }
  80. // Release the Unicode interface
  81. lpDP2->lpVtbl->Release(lpDP2);
  82. LEAVE_DPLOBBY();
  83. }
  84. return hr;
  85. } // DPL_A_Connect
  86. #undef DPF_MODNAME
  87. #define DPF_MODNAME "DPL_A_ConnectEx"
  88. HRESULT DPLAPI DPL_A_ConnectEx(LPDIRECTPLAYLOBBY lpDPL, DWORD dwFlags,
  89. REFIID riid, LPVOID * ppvObj, IUnknown FAR * lpUnk)
  90. {
  91. LPDIRECTPLAY2 lpDP2A = NULL;
  92. HRESULT hr;
  93. DPF(7, "Entering DPL_A_ConnectEx");
  94. DPF(9, "Parameters: 0x%08x, 0x%08x, iid, 0x%08x, 0x%08x",
  95. lpDPL, dwFlags, ppvObj, lpUnk);
  96. hr = DPL_A_Connect(lpDPL, dwFlags, &lpDP2A, lpUnk);
  97. if(SUCCEEDED(hr))
  98. {
  99. hr = DP_QueryInterface((LPDIRECTPLAY)lpDP2A, riid, ppvObj);
  100. if(FAILED(hr))
  101. {
  102. DPF_ERRVAL("Failed calling QueryInterface, hr = 0x%08x", hr);
  103. }
  104. // Release the DP2 object
  105. DP_Release((LPDIRECTPLAY)lpDP2A);
  106. }
  107. return hr;
  108. } // DPL_A_ConnectEx
  109. #undef DPF_MODNAME
  110. #define DPF_MODNAME "DPL_A_EnumLocalApplications"
  111. HRESULT DPLAPI DPL_A_EnumLocalApplications(LPDIRECTPLAYLOBBY lpDPL,
  112. LPDPLENUMLOCALAPPLICATIONSCALLBACK lpCallback,
  113. LPVOID lpContext, DWORD dwFlags)
  114. {
  115. HRESULT hr;
  116. DPF(7, "Entering DPL_A_EnumLocalApplications");
  117. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x, 0x%08x",
  118. lpDPL, lpCallback, lpContext, dwFlags);
  119. ENTER_DPLOBBY();
  120. // Set the ANSI flag to TRUE and call the internal function
  121. hr = PRV_EnumLocalApplications(lpDPL, lpCallback, lpContext,
  122. dwFlags, TRUE);
  123. LEAVE_DPLOBBY();
  124. return hr;
  125. } // DPL_A_EnumLocalApplications
  126. #undef DPF_MODNAME
  127. #define DPF_MODNAME "DPL_A_GetConnectionSettings"
  128. HRESULT DPLAPI DPL_A_GetConnectionSettings(LPDIRECTPLAYLOBBY lpDPL,
  129. DWORD dwGameID, LPVOID lpData, LPDWORD lpdwSize)
  130. {
  131. HRESULT hr;
  132. DPF(7, "Entering DPL_A_GetConnectionSettings");
  133. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x, 0x%08x",
  134. lpDPL, dwGameID, lpData, lpdwSize);
  135. ENTER_DPLOBBY();
  136. // Set the ANSI flag to TRUE and call the internal function
  137. hr = PRV_GetConnectionSettings(lpDPL, dwGameID, lpData,
  138. lpdwSize, TRUE);
  139. LEAVE_DPLOBBY();
  140. return hr;
  141. } // DPL_A_GetConnectionSettings
  142. #undef DPF_MODNAME
  143. #define DPF_MODNAME "DPL_A_GetGroupConnectionSettings"
  144. HRESULT DPLAPI DPL_A_GetGroupConnectionSettings(LPDIRECTPLAY lpDP,
  145. DWORD dwFlags, DPID idGroup, LPVOID lpData, LPDWORD lpdwSize)
  146. {
  147. HRESULT hr;
  148. DPF(7, "Entering DPL_A_GetGroupConnectionSettings");
  149. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x",
  150. lpDP, dwFlags, idGroup, lpData, lpdwSize);
  151. ENTER_LOBBY_ALL();
  152. // Set the ANSI flag to TRUE and call the internal function
  153. hr = PRV_GetGroupConnectionSettings(lpDP, dwFlags, idGroup,
  154. lpData, lpdwSize);
  155. if(SUCCEEDED(hr))
  156. {
  157. // Now convert the DPLCONNECTION to ANSI in place
  158. hr = PRV_ConvertDPLCONNECTIONToAnsiInPlace((LPDPLCONNECTION)lpData,
  159. lpdwSize, 0);
  160. if(FAILED(hr))
  161. {
  162. DPF_ERRVAL("Failed converting DPLCONNECTION struct to ANSI, hr = 0x%08x", hr);
  163. }
  164. }
  165. LEAVE_LOBBY_ALL();
  166. return hr;
  167. } // DPL_A_GetGroupConnectionSettings
  168. #undef DPF_MODNAME
  169. #define DPF_MODNAME "DPL_A_RegisterApplication"
  170. HRESULT DPLAPI DPL_A_RegisterApplication(LPDIRECTPLAYLOBBY lpDPL,
  171. DWORD dwFlags, LPVOID lpvDesc)
  172. {
  173. LPDPLOBBYI_DPLOBJECT this;
  174. LPDPAPPLICATIONDESC lpDescW = NULL;
  175. HRESULT hr = DP_OK;
  176. LPDPAPPLICATIONDESC lpDesc=(LPDPAPPLICATIONDESC)lpvDesc;
  177. DPF(7, "Entering DPL_A_RegisterApplication");
  178. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x",
  179. lpDPL, dwFlags, lpDesc);
  180. ENTER_DPLOBBY();
  181. TRY
  182. {
  183. // We only need to validate the interface pointer here. Everything else
  184. // will get validated by the main function.
  185. if( !VALID_DPLOBBY_INTERFACE( lpDPL ))
  186. {
  187. LEAVE_DPLOBBY();
  188. return DPERR_INVALIDINTERFACE;
  189. }
  190. this = DPLOBJECT_FROM_INTERFACE(lpDPL);
  191. if( !VALID_DPLOBBY_PTR( this ) )
  192. {
  193. LEAVE_DPLOBBY();
  194. return DPERR_INVALIDOBJECT;
  195. }
  196. if(dwFlags)
  197. {
  198. LEAVE_DPLOBBY();
  199. return DPERR_INVALIDFLAGS;
  200. }
  201. // Validate the ApplicationDesc struct
  202. hr = PRV_ValidateDPAPPLICATIONDESC(lpDesc, TRUE);
  203. if(FAILED(hr))
  204. {
  205. LEAVE_DPLOBBY();
  206. DPF_ERR("Invalid DPAPPLICATIONDESC structure");
  207. return hr;
  208. }
  209. }
  210. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  211. {
  212. LEAVE_DPLOBBY();
  213. DPF_ERR( "Exception encountered validating parameters" );
  214. return DPERR_INVALIDPARAMS;
  215. }
  216. // If we're on an ANSI platform, just write the stuff in the registry.
  217. // If it's not, we need to convert the DPAPPLICATIONDESC struct to Unicode
  218. if(OS_IsPlatformUnicode())
  219. {
  220. // Convert the APPDESC struct to Unicode
  221. hr = PRV_ConvertDPAPPLICATIONDESCToUnicode(lpDesc, &lpDescW);
  222. if(FAILED(hr))
  223. {
  224. DPF_ERRVAL("Unable to convert DPAPPLICATIONDESC to Unicode, hr = 0x%08x", hr);
  225. goto ERROR_REGISTERAPPLICATION;
  226. }
  227. // Write to the registry
  228. hr = PRV_WriteAppDescInRegistryUnicode(lpDescW);
  229. // Free our APPDESC structure
  230. PRV_FreeLocalDPAPPLICATIONDESC(lpDescW);
  231. }
  232. else
  233. {
  234. // Just write to the registry
  235. hr = PRV_WriteAppDescInRegistryAnsi(lpDesc);
  236. }
  237. if(FAILED(hr))
  238. {
  239. DPF_ERRVAL("Failed writing ApplicationDesc to registry, hr = 0x%08x", hr);
  240. }
  241. ERROR_REGISTERAPPLICATION:
  242. LEAVE_DPLOBBY();
  243. return hr;
  244. } // DPL_A_RegisterApplication
  245. #undef DPF_MODNAME
  246. #define DPF_MODNAME "PRV_FreeInternalDPLCONNECTION"
  247. void PRV_FreeInternalDPLCONNECTION(LPDPLCONNECTION lpConn)
  248. {
  249. LPDPSESSIONDESC2 lpsd;
  250. LPDPNAME lpn;
  251. DPF(7, "Entering PRV_FreeInternalDPLCONNECTION");
  252. DPF(9, "Parameters: 0x%08x", lpConn);
  253. if(!lpConn)
  254. return;
  255. if(lpConn->lpSessionDesc)
  256. {
  257. lpsd = lpConn->lpSessionDesc;
  258. if(lpsd->lpszSessionName)
  259. DPMEM_FREE(lpsd->lpszSessionName);
  260. if(lpsd->lpszPassword)
  261. DPMEM_FREE(lpsd->lpszPassword);
  262. DPMEM_FREE(lpsd);
  263. }
  264. if(lpConn->lpPlayerName)
  265. {
  266. lpn = lpConn->lpPlayerName;
  267. if(lpn->lpszShortName)
  268. DPMEM_FREE(lpn->lpszShortName);
  269. if(lpn->lpszLongName)
  270. DPMEM_FREE(lpn->lpszLongName);
  271. DPMEM_FREE(lpn);
  272. }
  273. DPMEM_FREE(lpConn);
  274. } // PRV_FreeInternalDPLCONNECTION
  275. #undef DPF_MODNAME
  276. #define DPF_MODNAME "DPL_A_RunApplication"
  277. HRESULT DPLAPI DPL_A_RunApplication(LPDIRECTPLAYLOBBY lpDPL, DWORD dwFlags,
  278. LPDWORD lpdwGameID, LPDPLCONNECTION lpConnA,
  279. HANDLE hReceiveEvent)
  280. {
  281. LPDPLCONNECTION lpConnW = NULL;
  282. HRESULT hr;
  283. DPF(7, "Entering DPL_A_RunApplication");
  284. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x",
  285. lpDPL, dwFlags, lpdwGameID, lpConnA, hReceiveEvent);
  286. ENTER_DPLOBBY();
  287. // Validate the DPLCONNECTION structure and it's members
  288. hr = PRV_ValidateDPLCONNECTION(lpConnA, TRUE);
  289. if(FAILED(hr))
  290. {
  291. LEAVE_DPLOBBY();
  292. return hr;
  293. }
  294. // Convert the ANSI DPLCONNECTION structure to Unicode
  295. hr = PRV_ConvertDPLCONNECTIONToUnicode(lpConnA, &lpConnW);
  296. if(FAILED(hr))
  297. {
  298. DPF_ERR("Failed to convert ANSI DPLCONNECTION structure to Unicode (temp)");
  299. LEAVE_DPLOBBY();
  300. return hr;
  301. }
  302. LEAVE_DPLOBBY();
  303. hr = DPL_RunApplication(lpDPL, dwFlags, lpdwGameID, lpConnW,
  304. hReceiveEvent);
  305. ENTER_DPLOBBY();
  306. // Free our temporary Unicode DPLCONNECTION structure
  307. PRV_FreeInternalDPLCONNECTION(lpConnW);
  308. LEAVE_DPLOBBY();
  309. return hr;
  310. } // DPL_A_RunApplication
  311. #undef DPF_MODNAME
  312. #define DPF_MODNAME "DPL_A_SetConnectionSettings"
  313. HRESULT DPLAPI DPL_A_SetConnectionSettings(LPDIRECTPLAYLOBBY lpDPL,
  314. DWORD dwFlags, DWORD dwGameID,
  315. LPDPLCONNECTION lpConnA)
  316. {
  317. HRESULT hr;
  318. LPDPLCONNECTION lpConnW = NULL;
  319. DPF(7, "Entering DPL_A_SetConnectionSettings");
  320. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x, 0x%08x",
  321. lpDPL, dwFlags, dwGameID, lpConnA);
  322. ENTER_DPLOBBY();
  323. // Validate the DPLCONNECTION structure and it's members
  324. hr = PRV_ValidateDPLCONNECTION(lpConnA, TRUE);
  325. if(FAILED(hr))
  326. {
  327. LEAVE_DPLOBBY();
  328. return hr;
  329. }
  330. // Conver the ANSI DPLCONNECTION struct to Unicode
  331. hr = PRV_ConvertDPLCONNECTIONToUnicode(lpConnA, &lpConnW);
  332. if(FAILED(hr))
  333. {
  334. DPF_ERR("Unable to convert DPLCONNECTION structure to Unicode");
  335. LEAVE_DPLOBBY();
  336. return hr;
  337. }
  338. // Set the ANSI flag to TRUE and call the internal function
  339. hr = PRV_SetConnectionSettings(lpDPL, dwFlags, dwGameID, lpConnW);
  340. // Free our temporary Unicode DPLCONNECTION structure
  341. PRV_FreeInternalDPLCONNECTION(lpConnW);
  342. LEAVE_DPLOBBY();
  343. return hr;
  344. } // DPL_A_SetConnectionSettings
  345. #undef DPF_MODNAME
  346. #define DPF_MODNAME "DPL_A_SetGroupConnectionSettings"
  347. HRESULT DPLAPI DPL_A_SetGroupConnectionSettings(LPDIRECTPLAY lpDP,
  348. DWORD dwFlags, DPID idGroup,
  349. LPDPLCONNECTION lpConnA)
  350. {
  351. HRESULT hr;
  352. LPDPLCONNECTION lpConnW = NULL;
  353. DPF(7, "Entering DPL_A_SetGroupConnectionSettings");
  354. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x, 0x%08x",
  355. lpDP, dwFlags, idGroup, lpConnA);
  356. ENTER_LOBBY_ALL();
  357. // Validate the DPLCONNECTION structure and it's members
  358. hr = PRV_ValidateDPLCONNECTION(lpConnA, TRUE);
  359. if(FAILED(hr))
  360. {
  361. LEAVE_LOBBY_ALL();
  362. return hr;
  363. }
  364. // Conver the ANSI DPLCONNECTION struct to Unicode
  365. hr = PRV_ConvertDPLCONNECTIONToUnicode(lpConnA, &lpConnW);
  366. if(FAILED(hr))
  367. {
  368. DPF_ERR("Unable to convert DPLCONNECTION structure to Unicode");
  369. LEAVE_LOBBY_ALL();
  370. return hr;
  371. }
  372. // Set the ANSI flag to TRUE and call the internal function
  373. hr = PRV_SetGroupConnectionSettings(lpDP, dwFlags, idGroup,
  374. lpConnW, TRUE);
  375. // Free our temporary Unicode DPLCONNECTION structure
  376. PRV_FreeInternalDPLCONNECTION(lpConnW);
  377. LEAVE_LOBBY_ALL();
  378. return hr;
  379. } // DPL_A_SetGroupConnectionSettings