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.

1199 lines
34 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: addtcp.cpp
  6. * Content: DirectPlay8Address TCP interace file
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 02/04/2000 rmt Created
  12. * 02/12/2000 rmt Split Get into GetByName and GetByIndex
  13. * 02/17/2000 rmt Parameter validation work
  14. * 02/21/2000 rmt Updated to make core Unicode and remove ANSI calls
  15. * 03/21/2000 rmt Renamed all DirectPlayAddress8's to DirectPlay8Addresses
  16. * Added support for the new ANSI type
  17. * Added SetEqual function
  18. * 03/24/2000 rmt Added IsEqual function
  19. * 04/21/2000 rmt Bug #32952 - Does not run on Win95 GOLD pre-IE4
  20. * 05/01/2000 rmt Bug #33074 - Debug accessing invalid memory
  21. * 05/17/2000 rmt Bug #35051 - Incorrect function names in debug spew
  22. * 06/09/2000 rmt Updates to split CLSID and allow whistler compat
  23. * 07/21/2000 rmt Fixed bug w/directplay 4 address parsing
  24. * 02/07/2001 rmt WINBUG #290631 - IA64: DirectPlay: Addressing BuildFromDPADDRESS should always return UNSUPPORTED
  25. *
  26. *@@END_MSINTERNAL
  27. *
  28. ***************************************************************************/
  29. #include "dnaddri.h"
  30. typedef STDMETHODIMP BaseQueryInterface( IDirectPlay8Address *pInterface, DPNAREFIID riid, LPVOID *ppvObj );
  31. typedef STDMETHODIMP_(ULONG) BaseAddRef( IDirectPlay8Address *pInterface );
  32. typedef STDMETHODIMP_(ULONG) BaseRelease( IDirectPlay8Address *pInterface );
  33. //
  34. // VTable for client interface
  35. //
  36. IDirectPlay8AddressVtbl DP8A_BaseVtbl =
  37. {
  38. (BaseQueryInterface*) DP8A_QueryInterface,
  39. (BaseAddRef*) DP8A_AddRef,
  40. (BaseRelease*) DP8A_Release,
  41. DP8A_BuildFromURLW,
  42. DP8A_BuildFromURLA,
  43. DP8A_Duplicate,
  44. DP8A_SetEqual,
  45. DP8A_IsEqual,
  46. DP8A_Clear,
  47. DP8A_GetURLW,
  48. DP8A_GetURLA,
  49. DP8A_GetSP,
  50. DP8A_GetUserData,
  51. DP8A_SetSP,
  52. DP8A_SetUserData,
  53. DP8A_GetNumComponents,
  54. DP8A_GetComponentByNameW,
  55. DP8A_GetComponentByIndexW,
  56. DP8A_AddComponentW,
  57. DP8A_GetDevice,
  58. DP8A_SetDevice,
  59. DP8A_BuildFromDirectPlay4Address
  60. };
  61. //**********************************************************************
  62. // Function prototypes
  63. //**********************************************************************
  64. #undef DPF_MODNAME
  65. #define DPF_MODNAME "DP8A_IsEqual"
  66. STDMETHODIMP DP8A_IsEqual( IDirectPlay8Address *pInterface, PDIRECTPLAY8ADDRESS pdp8ExternalAddress )
  67. {
  68. HRESULT hr;
  69. WCHAR *wszFirstURL = NULL,
  70. *wszSecondURL = NULL;
  71. DWORD dwFirstBufferSize = 0,
  72. dwSecondBuffersize = 0;
  73. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  74. #ifndef DPNBUILD_NOPARAMVAL
  75. if( pInterface == NULL ||
  76. !DP8A_VALID( pInterface ) )
  77. {
  78. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  79. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  80. }
  81. if( pdp8ExternalAddress == NULL )
  82. {
  83. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified" );
  84. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  85. }
  86. if( !DP8A_VALID( pdp8ExternalAddress ) )
  87. {
  88. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid object" );
  89. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  90. }
  91. #endif // !DPNBUILD_NOPARAMVAL
  92. hr = IDirectPlay8Address_GetURLW( pInterface, wszFirstURL, &dwFirstBufferSize );
  93. if( hr != DPNERR_BUFFERTOOSMALL )
  94. {
  95. DPFX(DPFPREP, 0, "Could not get URL size for current object hr=[0x%lx]", hr );
  96. goto ISEQUAL_ERROR;
  97. }
  98. wszFirstURL = (WCHAR*) DNMalloc(dwFirstBufferSize * sizeof(WCHAR));
  99. if( wszFirstURL == NULL )
  100. {
  101. DPFX(DPFPREP, 0, "Error allocating memory hr=[0x%lx]", hr );
  102. goto ISEQUAL_ERROR;
  103. }
  104. hr = IDirectPlay8Address_GetURLW( pInterface, wszFirstURL, &dwFirstBufferSize );
  105. if( FAILED( hr ) )
  106. {
  107. DPFX(DPFPREP, 0, "Could not get URL for current object hr=[0x%lx]", hr );
  108. goto ISEQUAL_ERROR;
  109. }
  110. hr = IDirectPlay8Address_GetURLW( pdp8ExternalAddress, wszSecondURL, &dwSecondBuffersize );
  111. if( hr != DPNERR_BUFFERTOOSMALL )
  112. {
  113. DPFX(DPFPREP, 0, "Could not get URL size for exterior object hr=[0x%lx]", hr );
  114. goto ISEQUAL_ERROR;
  115. }
  116. wszSecondURL = (WCHAR*) DNMalloc(dwSecondBuffersize * sizeof(WCHAR));
  117. if( wszSecondURL == NULL )
  118. {
  119. DPFX(DPFPREP, 0, "Error allocating memory hr=[0x%lx]", hr );
  120. goto ISEQUAL_ERROR;
  121. }
  122. hr = IDirectPlay8Address_GetURLW( pdp8ExternalAddress, wszSecondURL, &dwSecondBuffersize );
  123. if( FAILED( hr ) )
  124. {
  125. DPFX(DPFPREP, 0, "Could not get URL for exterior object hr=[0x%lx]", hr );
  126. goto ISEQUAL_ERROR;
  127. }
  128. if( _wcsicmp( wszFirstURL, wszSecondURL ) == 0 )
  129. {
  130. hr = DPNSUCCESS_EQUAL;
  131. }
  132. else
  133. {
  134. hr = DPNSUCCESS_NOTEQUAL;
  135. }
  136. ISEQUAL_ERROR:
  137. if( wszFirstURL != NULL )
  138. DNFree(wszFirstURL);
  139. if( wszSecondURL != NULL )
  140. DNFree(wszSecondURL);
  141. DP8A_RETURN( hr );
  142. }
  143. #undef DPF_MODNAME
  144. #define DPF_MODNAME "DP8A_SetEqual"
  145. STDMETHODIMP DP8A_SetEqual( IDirectPlay8Address *pInterface, PDIRECTPLAY8ADDRESS pdp8ExternalAddress )
  146. {
  147. HRESULT hr;
  148. WCHAR *wszURLBuffer = NULL;
  149. DWORD dwBufferSize = 0;
  150. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  151. #ifndef DPNBUILD_NOPARAMVAL
  152. if( pInterface == NULL ||
  153. !DP8A_VALID( pInterface ) )
  154. {
  155. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  156. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  157. }
  158. if( pdp8ExternalAddress == NULL )
  159. {
  160. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified" );
  161. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  162. }
  163. if( !DP8A_VALID( pdp8ExternalAddress ) )
  164. {
  165. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid object" );
  166. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  167. }
  168. #endif // !DPNBUILD_NOPARAMVAL
  169. DP8ADDRESSOBJECT *pdp8Address = (DP8ADDRESSOBJECT *) GET_OBJECT_FROM_INTERFACE( pInterface );
  170. // Get ourselves a reference for duration of the call
  171. IDirectPlay8Address_AddRef(pdp8ExternalAddress);
  172. hr = IDirectPlay8Address_GetURLW( pdp8ExternalAddress, wszURLBuffer, &dwBufferSize );
  173. if( hr != DPNERR_BUFFERTOOSMALL )
  174. {
  175. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Error getting contents of passed address hr=0x%x", hr );
  176. goto SETEQUAL_CLEANUP;
  177. }
  178. wszURLBuffer = (WCHAR*) DNMalloc(dwBufferSize * sizeof(WCHAR));
  179. if( wszURLBuffer == NULL )
  180. {
  181. hr = DPNERR_OUTOFMEMORY;
  182. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Error allocating memory" );
  183. goto SETEQUAL_CLEANUP;
  184. }
  185. hr = IDirectPlay8Address_GetURLW( pdp8ExternalAddress, wszURLBuffer, &dwBufferSize );
  186. if( FAILED( hr ) )
  187. {
  188. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Error getting contents of passed address w/buffer hr=0x%x", hr );
  189. goto SETEQUAL_CLEANUP;
  190. }
  191. hr = pdp8Address->SetURL( wszURLBuffer );
  192. if( FAILED( hr ) )
  193. {
  194. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Error setting address to match passed address hr=0x%x", hr );
  195. goto SETEQUAL_CLEANUP;
  196. }
  197. SETEQUAL_CLEANUP:
  198. IDirectPlay8Address_Release(pdp8ExternalAddress);
  199. if( wszURLBuffer != NULL )
  200. DNFree(wszURLBuffer);
  201. DP8A_RETURN( hr );
  202. }
  203. #undef DPF_MODNAME
  204. #define DPF_MODNAME "DP8A_BuildFromDirectPlay4Address"
  205. STDMETHODIMP DP8A_BuildFromDirectPlay4Address( IDirectPlay8Address *pInterface, void * pvDataBuffer, DWORD dwDataSize )
  206. {
  207. #ifdef DPNBUILD_NOLEGACYDP
  208. DPFX(DPFPREP, DP8A_ERRORLEVEL, "BuildFromDirectPlay4Address() is not supported!" );
  209. DP8A_RETURN( DPNERR_UNSUPPORTED );
  210. #else // ! DPNBUILD_NOLEGACYDP
  211. HRESULT hr;
  212. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  213. #ifndef DPNBUILD_NOPARAMVAL
  214. if( pInterface == NULL ||
  215. !DP8A_VALID( pInterface ) )
  216. {
  217. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  218. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  219. }
  220. if( dwDataSize == 0 )
  221. {
  222. DPFX(DPFPREP, DP8A_ERRORLEVEL, "0 length addresses are not allowed" );
  223. return DPNERR_INVALIDPARAM;
  224. }
  225. if( pvDataBuffer == NULL ||
  226. !DNVALID_READPTR( pvDataBuffer, dwDataSize ) )
  227. {
  228. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Specified buffer is invalid" );
  229. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  230. }
  231. #endif // !DPNBUILD_NOPARAMVAL
  232. DP8ADDRESSOBJECT *pdp8Address = (DP8ADDRESSOBJECT *) GET_OBJECT_FROM_INTERFACE( pInterface );
  233. hr = pdp8Address->SetDirectPlay4Address( pvDataBuffer, dwDataSize );
  234. DP8A_RETURN( hr );
  235. #endif // ! DPNBUILD_NOLEGACYDP
  236. }
  237. // DP8A_BuildFromURLA
  238. //
  239. // Initializes this object with URL specified in ANSI
  240. //
  241. #undef DPF_MODNAME
  242. #define DPF_MODNAME "DP8A_BuildFromURLA"
  243. STDMETHODIMP DP8A_BuildFromURLA( IDirectPlay8Address *pInterface, CHAR * pszAddress )
  244. {
  245. HRESULT hr;
  246. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  247. #ifndef DPNBUILD_NOPARAMVAL
  248. if( pInterface == NULL ||
  249. !DP8A_VALID( pInterface ) )
  250. {
  251. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  252. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  253. }
  254. if( pszAddress == NULL )
  255. {
  256. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer to address. An address must be specified" );
  257. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  258. }
  259. if( !DNVALID_STRING_A( pszAddress ) )
  260. {
  261. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid string specified for address" );
  262. DP8A_RETURN( DPNERR_INVALIDSTRING );
  263. }
  264. #endif // !DPNBUILD_NOPARAMVAL
  265. DP8ADDRESSOBJECT *pdp8Address = (DP8ADDRESSOBJECT *) GET_OBJECT_FROM_INTERFACE( pInterface );
  266. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pszAddress = %hs", pszAddress );
  267. WCHAR *szShadowBuffer = NULL;
  268. DWORD dwStrSize = 0;
  269. if( pszAddress != NULL )
  270. {
  271. dwStrSize = strlen(pszAddress)+1;
  272. szShadowBuffer = (WCHAR*) DNMalloc(dwStrSize * sizeof(WCHAR));
  273. if( szShadowBuffer == NULL )
  274. {
  275. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Error allocating memory" );
  276. hr = DPNERR_OUTOFMEMORY;
  277. goto BUILDFROMURLW_RETURN;
  278. }
  279. if( FAILED( hr = STR_jkAnsiToWide( szShadowBuffer, pszAddress, dwStrSize ) ) )
  280. {
  281. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Error converting URL to ANSI hr=0x%x", hr );
  282. hr = DPNERR_CONVERSION;
  283. goto BUILDFROMURLW_RETURN;
  284. }
  285. }
  286. hr = pdp8Address->SetURL( szShadowBuffer );
  287. BUILDFROMURLW_RETURN:
  288. if( szShadowBuffer )
  289. DNFree(szShadowBuffer);
  290. DP8A_RETURN( hr );
  291. }
  292. // DP8A_BuildFromURLW
  293. //
  294. // Initializes this object with URL specified in Unicode
  295. //
  296. #undef DPF_MODNAME
  297. #define DPF_MODNAME "DP8A_BuildFromURLW"
  298. STDMETHODIMP DP8A_BuildFromURLW( IDirectPlay8Address *pInterface, WCHAR * pwszAddress )
  299. {
  300. HRESULT hr;
  301. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  302. #ifndef DPNBUILD_NOPARAMVAL
  303. if( pInterface == NULL ||
  304. !DP8A_VALID( pInterface ) )
  305. {
  306. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  307. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  308. }
  309. if( pwszAddress == NULL )
  310. {
  311. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer to address. An address must be specified" );
  312. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  313. }
  314. if( !DNVALID_STRING_W( pwszAddress ) )
  315. {
  316. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid string specified for address" );
  317. DP8A_RETURN( DPNERR_INVALIDSTRING );
  318. }
  319. #endif // !DPNBUILD_NOPARAMVAL
  320. DP8ADDRESSOBJECT *pdp8Address = (DP8ADDRESSOBJECT *) GET_OBJECT_FROM_INTERFACE( pInterface );
  321. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pwszAddress = %ls", pwszAddress );
  322. hr = pdp8Address->SetURL( pwszAddress );
  323. DP8A_RETURN( hr );
  324. }
  325. // DP8A_Duplicate
  326. //
  327. // Creates and initializes another address object as a duplicate to this one.
  328. //
  329. #undef DPF_MODNAME
  330. #define DPF_MODNAME "DP8A_Duplicate"
  331. STDMETHODIMP DP8A_Duplicate( IDirectPlay8Address *pInterface, PDIRECTPLAY8ADDRESS *ppInterface )
  332. {
  333. HRESULT hr;
  334. DP8ADDRESSOBJECT *pdp8AddressSource;
  335. LPDIRECTPLAY8ADDRESS lpdp8Address = NULL;
  336. DP8ADDRESSOBJECT *pdp8AddressDest;
  337. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  338. #ifndef DPNBUILD_NOPARAMVAL
  339. if( pInterface == NULL ||
  340. !DP8A_VALID( pInterface ) )
  341. {
  342. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  343. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  344. }
  345. if( ppInterface == NULL ||
  346. !DNVALID_WRITEPTR( ppInterface, sizeof(LPVOID) ) )
  347. {
  348. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer to pointer specified in ppInterface" );
  349. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  350. }
  351. #endif // !DPNBUILD_NOPARAMVAL
  352. pdp8AddressSource = (DP8ADDRESSOBJECT *) GET_OBJECT_FROM_INTERFACE( pInterface );
  353. DPFX(DPFPREP, DP8A_PARAMLEVEL, "ppInterface = 0x%p", ppInterface );
  354. #ifdef DPNBUILD_LIBINTERFACE
  355. hr = DP8ACF_CreateInstance( IID_IDirectPlay8Address,
  356. (void **) &lpdp8Address );
  357. #else // ! DPNBUILD_LIBINTERFACE
  358. hr = COM_CoCreateInstance( CLSID_DirectPlay8Address,
  359. NULL,
  360. CLSCTX_INPROC_SERVER,
  361. IID_IDirectPlay8Address,
  362. (void **) &lpdp8Address,
  363. FALSE );
  364. #endif // ! DPNBUILD_LIBINTERFACE
  365. if( FAILED( hr ) )
  366. {
  367. DPFX(DPFPREP, DP8A_ERRORLEVEL, "CoCreate failed hr=0x%x", hr );
  368. goto DUPLICATE_FAIL;
  369. }
  370. pdp8AddressDest = (DP8ADDRESSOBJECT *) GET_OBJECT_FROM_INTERFACE( lpdp8Address );
  371. hr = pdp8AddressDest->Copy( pdp8AddressSource );
  372. if( FAILED( hr ) )
  373. {
  374. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Copy failed hr=0x%x", hr );
  375. goto DUPLICATE_FAIL;
  376. }
  377. *ppInterface = lpdp8Address;
  378. return DPN_OK;
  379. DUPLICATE_FAIL:
  380. if( lpdp8Address != NULL )
  381. IDirectPlay8Address_Release(lpdp8Address);
  382. return hr;
  383. }
  384. #undef DPF_MODNAME
  385. #define DPF_MODNAME "DP8A_GetURLA"
  386. STDMETHODIMP DP8A_GetURLA( IDirectPlay8Address *pInterface, CHAR * pszAddress, PDWORD pdwAddressSize )
  387. {
  388. HRESULT hr;
  389. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  390. #ifndef DPNBUILD_NOPARAMVAL
  391. if( pInterface == NULL ||
  392. !DP8A_VALID( pInterface ) )
  393. {
  394. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  395. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  396. }
  397. if( pdwAddressSize == NULL ||
  398. !DNVALID_WRITEPTR( pdwAddressSize, sizeof(DWORD) ) )
  399. {
  400. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for address size" );
  401. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  402. }
  403. if( *pdwAddressSize > 0 &&
  404. (pszAddress == NULL ||
  405. !DNVALID_WRITEPTR( pszAddress, (*pdwAddressSize) ) ) )
  406. {
  407. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for address" );
  408. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  409. }
  410. #endif // !DPNBUILD_NOPARAMVAL
  411. DP8ADDRESSOBJECT *pdp8Address = (DP8ADDRESSOBJECT *) GET_OBJECT_FROM_INTERFACE( pInterface );
  412. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pwszAddress = 0x%p pdwAddressSize = 0x%p (%u)",
  413. pszAddress, pdwAddressSize, *pdwAddressSize );
  414. hr = pdp8Address->BuildURLA( pszAddress, pdwAddressSize );
  415. DP8A_RETURN( hr );
  416. }
  417. // DP8A_GetURLW
  418. //
  419. // Retrieves the URL represented by this object in Unicode format
  420. //
  421. #undef DPF_MODNAME
  422. #define DPF_MODNAME "DP8A_GetURLW"
  423. STDMETHODIMP DP8A_GetURLW( IDirectPlay8Address *pInterface, WCHAR * pwszAddress, PDWORD pdwAddressSize )
  424. {
  425. HRESULT hr;
  426. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  427. #ifndef DPNBUILD_NOPARAMVAL
  428. if( pInterface == NULL ||
  429. !DP8A_VALID( pInterface ) )
  430. {
  431. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  432. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  433. }
  434. if( pdwAddressSize == NULL ||
  435. !DNVALID_WRITEPTR( pdwAddressSize, sizeof(DWORD) ) )
  436. {
  437. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for address size" );
  438. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  439. }
  440. if( *pdwAddressSize > 0 &&
  441. (pwszAddress == NULL ||
  442. !DNVALID_WRITEPTR( pwszAddress, (*pdwAddressSize)*sizeof(WCHAR) ) ) )
  443. {
  444. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for address" );
  445. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  446. }
  447. #endif // !DPNBUILD_NOPARAMVAL
  448. DP8ADDRESSOBJECT *pdp8Address = (DP8ADDRESSOBJECT *) GET_OBJECT_FROM_INTERFACE( pInterface );
  449. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pwszAddress = 0x%p pdwAddressSize = 0x%p (%u)",
  450. pwszAddress, pdwAddressSize, *pdwAddressSize );
  451. hr = pdp8Address->BuildURLW( pwszAddress, pdwAddressSize );
  452. DP8A_RETURN( hr );
  453. }
  454. #undef DPF_MODNAME
  455. #define DPF_MODNAME "DP8A_GetSP"
  456. STDMETHODIMP DP8A_GetSP( IDirectPlay8Address *pInterface, GUID * pguidSP )
  457. {
  458. #ifdef DPNBUILD_ONLYONESP
  459. DPFX(DPFPREP, 0, "Retrieving service provider GUID is not supported!");
  460. return DPNERR_UNSUPPORTED;
  461. #else // ! DPNBUILD_ONLYONESP
  462. HRESULT hr;
  463. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  464. #ifndef DPNBUILD_NOPARAMVAL
  465. if( pInterface == NULL ||
  466. !DP8A_VALID( pInterface ) )
  467. {
  468. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  469. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  470. }
  471. if( pguidSP == NULL ||
  472. !DNVALID_WRITEPTR( pguidSP, sizeof( GUID ) ) )
  473. {
  474. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pguidSP" );
  475. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  476. }
  477. #endif // !DPNBUILD_NOPARAMVAL
  478. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  479. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pguidSP = 0x%p ", pguidSP );
  480. hr = pdp8Address->GetSP( pguidSP );
  481. DP8A_RETURN( hr );
  482. #endif // ! DPNBUILD_ONLYONESP
  483. }
  484. #undef DPF_MODNAME
  485. #define DPF_MODNAME "DP8A_GetUserData"
  486. STDMETHODIMP DP8A_GetUserData( IDirectPlay8Address *pInterface, void * pBuffer, PDWORD pdwBufferSize )
  487. {
  488. HRESULT hr;
  489. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  490. #ifndef DPNBUILD_NOPARAMVAL
  491. if( pInterface == NULL ||
  492. !DP8A_VALID( pInterface ) )
  493. {
  494. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  495. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  496. }
  497. if( pdwBufferSize == NULL ||
  498. !DNVALID_WRITEPTR( pdwBufferSize, sizeof( DWORD ) ) )
  499. {
  500. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pdwBufferSize" );
  501. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  502. }
  503. if( *pdwBufferSize > 0 &&
  504. (pBuffer == NULL || !DNVALID_WRITEPTR( pBuffer, *pdwBufferSize ) ) )
  505. {
  506. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pBuffer" );
  507. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  508. }
  509. #endif // !DPNBUILD_NOPARAMVAL
  510. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  511. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pBuffer = 0x%p pdwBufferSize = 0x%p(%u) ", pBuffer, pdwBufferSize, *pdwBufferSize );
  512. hr = pdp8Address->GetUserData( pBuffer, pdwBufferSize );
  513. DP8A_RETURN( hr );
  514. }
  515. #undef DPF_MODNAME
  516. #define DPF_MODNAME "DP8A_SetSP"
  517. STDMETHODIMP DP8A_SetSP( IDirectPlay8Address *pInterface, const GUID * const pguidSP )
  518. {
  519. #ifdef DPNBUILD_ONLYONESP
  520. DPFX(DPFPREP, 0, "Setting service provider GUID is not supported!");
  521. return DPNERR_UNSUPPORTED;
  522. #else // ! DPNBUILD_ONLYONESP
  523. HRESULT hr;
  524. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  525. #ifndef DPNBUILD_NOPARAMVAL
  526. if( pInterface == NULL ||
  527. !DP8A_VALID( pInterface ) )
  528. {
  529. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  530. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  531. }
  532. if( pguidSP == NULL ||
  533. !DNVALID_READPTR( pguidSP, sizeof( GUID ) ) )
  534. {
  535. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pguidSP" );
  536. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  537. }
  538. #endif // !DPNBUILD_NOPARAMVAL
  539. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  540. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pguidSP = 0x%p", pguidSP );
  541. hr = pdp8Address->SetSP( pguidSP );
  542. DP8A_RETURN( hr );
  543. #endif // ! DPNBUILD_ONLYONESP
  544. }
  545. #undef DPF_MODNAME
  546. #define DPF_MODNAME "DP8A_GetDevice"
  547. STDMETHODIMP DP8A_GetDevice( IDirectPlay8Address *pInterface, GUID * pguidSP )
  548. {
  549. #ifdef DPNBUILD_ONLYONEADAPTER
  550. DPFX(DPFPREP, 0, "Retrieving device GUID is not supported!");
  551. return DPNERR_UNSUPPORTED;
  552. #else // ! DPNBUILD_ONLYONEADAPTER
  553. HRESULT hr;
  554. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  555. #ifndef DPNBUILD_NOPARAMVAL
  556. if( pInterface == NULL ||
  557. !DP8A_VALID( pInterface ) )
  558. {
  559. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  560. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  561. }
  562. if( pguidSP == NULL ||
  563. !DNVALID_WRITEPTR( pguidSP, sizeof( GUID ) ) )
  564. {
  565. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pguidDevice" );
  566. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  567. }
  568. #endif // !DPNBUILD_NOPARAMVAL
  569. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  570. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pguidDevice = 0x%p", pguidSP );
  571. hr = pdp8Address->GetDevice( pguidSP );
  572. DP8A_RETURN( hr );
  573. #endif // ! DPNBUILD_ONLYONEADAPTER
  574. }
  575. #undef DPF_MODNAME
  576. #define DPF_MODNAME "DP8A_SetDevice"
  577. STDMETHODIMP DP8A_SetDevice( IDirectPlay8Address *pInterface, const GUID * const pguidSP )
  578. {
  579. #ifdef DPNBUILD_ONLYONEADAPTER
  580. DPFX(DPFPREP, 0, "Setting device GUID is not supported!");
  581. return DPNERR_UNSUPPORTED;
  582. #else // ! DPNBUILD_ONLYONEADAPTER
  583. HRESULT hr;
  584. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  585. #ifndef DPNBUILD_NOPARAMVAL
  586. if( pInterface == NULL ||
  587. !DP8A_VALID( pInterface ) )
  588. {
  589. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  590. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  591. }
  592. if( pguidSP == NULL ||
  593. !DNVALID_READPTR( pguidSP, sizeof( GUID ) ) )
  594. {
  595. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pguidDevice" );
  596. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  597. }
  598. #endif // !DPNBUILD_NOPARAMVAL
  599. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  600. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pguidDevice = 0x%p", pguidSP );
  601. hr = pdp8Address->SetDevice( pguidSP );
  602. DP8A_RETURN( hr );
  603. #endif // ! DPNBUILD_ONLYONEADAPTER
  604. }
  605. #undef DPF_MODNAME
  606. #define DPF_MODNAME "DP8A_SetUserData"
  607. STDMETHODIMP DP8A_SetUserData( IDirectPlay8Address *pInterface, const void * const pBuffer, const DWORD dwBufferSize )
  608. {
  609. HRESULT hr;
  610. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  611. #ifndef DPNBUILD_NOPARAMVAL
  612. if( pInterface == NULL ||
  613. !DP8A_VALID( pInterface ) )
  614. {
  615. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  616. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  617. }
  618. if( dwBufferSize > 0 &&
  619. (pBuffer == NULL || !DNVALID_READPTR( pBuffer, dwBufferSize ) ) )
  620. {
  621. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pBuffer" );
  622. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  623. }
  624. #endif // !DPNBUILD_NOPARAMVAL
  625. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  626. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pBuffer = 0x%p dwBufferSize = %u", pBuffer, dwBufferSize );
  627. hr = pdp8Address->SetUserData( pBuffer, dwBufferSize );
  628. DP8A_RETURN( hr );
  629. }
  630. #undef DPF_MODNAME
  631. #define DPF_MODNAME "DP8A_GetNumComponents"
  632. STDMETHODIMP DP8A_GetNumComponents( IDirectPlay8Address *pInterface, PDWORD pdwNumComponents )
  633. {
  634. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  635. #ifndef DPNBUILD_NOPARAMVAL
  636. if( pInterface == NULL ||
  637. !DP8A_VALID( pInterface ) )
  638. {
  639. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  640. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  641. }
  642. if( pdwNumComponents == NULL ||
  643. !DNVALID_WRITEPTR( pdwNumComponents, sizeof(DWORD) ) )
  644. {
  645. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid ptr for num of components" );
  646. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  647. }
  648. #endif // !DPNBUILD_NOPARAMVAL
  649. const DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  650. *pdwNumComponents = pdp8Address->GetNumComponents();
  651. DP8A_RETURN( DPN_OK );
  652. }
  653. #undef DPF_MODNAME
  654. #define DPF_MODNAME "DP8A_GetComponentByNameW"
  655. STDMETHODIMP DP8A_GetComponentByNameW( IDirectPlay8Address *pInterface, const WCHAR * const pwszTag, void * pComponentBuffer, PDWORD pdwComponentSize, PDWORD pdwDataType )
  656. {
  657. HRESULT hr;
  658. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  659. #ifndef DPNBUILD_NOPARAMVAL
  660. if( pInterface == NULL ||
  661. !DP8A_VALID( pInterface ) )
  662. {
  663. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  664. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  665. }
  666. if( pwszTag == NULL )
  667. {
  668. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer to tag. A name must be specified" );
  669. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  670. }
  671. if( pdwComponentSize == NULL ||
  672. !DNVALID_WRITEPTR( pdwComponentSize, sizeof(DWORD)) )
  673. {
  674. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid Pointer to data size" );
  675. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  676. }
  677. if( pdwDataType == NULL ||
  678. !DNVALID_READPTR( pdwDataType, sizeof(DWORD)) )
  679. {
  680. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer to data type" );
  681. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  682. }
  683. if( *pdwComponentSize > 0 &&
  684. (pComponentBuffer == NULL || !DNVALID_WRITEPTR( pComponentBuffer, *pdwComponentSize ) ) )
  685. {
  686. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer to component data" );
  687. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  688. }
  689. if( !DNVALID_STRING_W( pwszTag ) )
  690. {
  691. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid string specified for tag" );
  692. DP8A_RETURN( DPNERR_INVALIDSTRING );
  693. }
  694. #endif // !DPNBUILD_NOPARAMVAL
  695. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  696. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pwszTag = 0x%p pComponentBuffer = 0x%p, pdwComponentSize = 0x%p, pdwDataType = 0x%p",
  697. (pwszTag==NULL) ? NULL : pwszTag, pComponentBuffer, pdwComponentSize, pdwDataType );
  698. hr = pdp8Address->GetElement( pwszTag, pComponentBuffer, pdwComponentSize, pdwDataType );
  699. DP8A_RETURN( hr );
  700. }
  701. #undef DPF_MODNAME
  702. #define DPF_MODNAME "DP8A_GetComponentByIndexW"
  703. STDMETHODIMP DP8A_GetComponentByIndexW( IDirectPlay8Address *pInterface,
  704. const DWORD dwComponentID, WCHAR * pwszTag, PDWORD pdwNameLen,
  705. void * pComponentBuffer, PDWORD pdwComponentSize, PDWORD pdwDataType )
  706. {
  707. HRESULT hr;
  708. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  709. #ifndef DPNBUILD_NOPARAMVAL
  710. if( pInterface == NULL ||
  711. !DP8A_VALID( pInterface ) )
  712. {
  713. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  714. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  715. }
  716. if( pdwNameLen == NULL || !DNVALID_WRITEPTR( pdwNameLen, sizeof(DWORD) ) )
  717. {
  718. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pdwNameLen" );
  719. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  720. }
  721. if( *pdwNameLen != 0 &&
  722. (pwszTag == NULL || !DNVALID_WRITEPTR( pwszTag, *pdwNameLen*sizeof(WCHAR) ) ) )
  723. {
  724. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pwszTag" );
  725. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  726. }
  727. if( pdwComponentSize == NULL || !DNVALID_WRITEPTR( pdwComponentSize, sizeof(DWORD) ) )
  728. {
  729. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pdwComponentSize" );
  730. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  731. }
  732. if( *pdwComponentSize != 0 &&
  733. (pComponentBuffer == NULL || !DNVALID_WRITEPTR( pComponentBuffer, *pdwComponentSize ) ) )
  734. {
  735. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pwszTag" );
  736. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  737. }
  738. if( pdwDataType == NULL || !DNVALID_WRITEPTR( pdwDataType, sizeof(DWORD) ) )
  739. {
  740. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for pdwDataType" );
  741. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  742. }
  743. #endif // !DPNBUILD_NOPARAMVAL
  744. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  745. DPFX(DPFPREP, DP8A_PARAMLEVEL, "dwComponentID = %u pwszTag = 0x%p pdwNameLen = 0x%p (%u) pComponentBuffer = 0x%p, pdwComponentSize = 0x%p (%u), pdwDataType = 0x%p",
  746. dwComponentID, pwszTag, pdwNameLen, *pdwNameLen, pComponentBuffer, pdwComponentSize, *pdwComponentSize, pdwDataType );
  747. hr = pdp8Address->GetElement( dwComponentID, pwszTag, pdwNameLen, pComponentBuffer, pdwComponentSize, pdwDataType );
  748. DP8A_RETURN( hr );
  749. }
  750. #undef DPF_MODNAME
  751. #define DPF_MODNAME "DP8A_AddComponentW"
  752. STDMETHODIMP DP8A_AddComponentW( IDirectPlay8Address *pInterface, const WCHAR * const pwszTag, const void * const pComponentData, const DWORD dwComponentSize, const DWORD dwDataType )
  753. {
  754. HRESULT hr;
  755. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  756. #ifndef DPNBUILD_NOPARAMVAL
  757. if( pInterface == NULL ||
  758. !DP8A_VALID( pInterface ) )
  759. {
  760. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  761. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  762. }
  763. if( pwszTag == NULL )
  764. {
  765. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer for tag string" );
  766. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  767. }
  768. if( pComponentData == NULL ||
  769. !DNVALID_READPTR( pComponentData, dwComponentSize ) )
  770. {
  771. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid pointer specified for component" );
  772. DP8A_RETURN( DPNERR_INVALIDPOINTER );
  773. }
  774. if( !DNVALID_STRING_W( pwszTag ) )
  775. {
  776. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid string specified for tag" );
  777. DP8A_RETURN( DPNERR_INVALIDSTRING );
  778. }
  779. if( dwDataType != DPNA_DATATYPE_STRING &&
  780. dwDataType != DPNA_DATATYPE_DWORD &&
  781. dwDataType != DPNA_DATATYPE_GUID &&
  782. dwDataType != DPNA_DATATYPE_BINARY &&
  783. dwDataType != DPNA_DATATYPE_STRING_ANSI )
  784. {
  785. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid datatype specified" );
  786. DP8A_RETURN( DPNERR_INVALIDPARAM );
  787. }
  788. if( dwDataType == DPNA_DATATYPE_STRING )
  789. {
  790. if( !DNVALID_STRING_W( (const WCHAR * const) pComponentData ) )
  791. {
  792. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid string component specified" );
  793. DP8A_RETURN( DPNERR_INVALIDSTRING );
  794. }
  795. if( ((wcslen( (const WCHAR * const) pComponentData)+1)*sizeof(WCHAR)) != dwComponentSize )
  796. {
  797. DPFX(DPFPREP, DP8A_ERRORLEVEL, "String size and component size don't match" );
  798. DP8A_RETURN( DPNERR_INVALIDPARAM );
  799. }
  800. }
  801. else if( dwDataType == DPNA_DATATYPE_STRING_ANSI )
  802. {
  803. if( !DNVALID_STRING_A( (const CHAR * const) pComponentData ) )
  804. {
  805. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid string component specified" );
  806. DP8A_RETURN( DPNERR_INVALIDSTRING );
  807. }
  808. if( ((strlen( (const CHAR * const) pComponentData)+1)*sizeof(char)) != dwComponentSize )
  809. {
  810. DPFX(DPFPREP, DP8A_ERRORLEVEL, "String size and component size don't match" );
  811. DP8A_RETURN( DPNERR_INVALIDPARAM );
  812. }
  813. }
  814. else if( dwDataType == DPNA_DATATYPE_DWORD )
  815. {
  816. if( dwComponentSize != sizeof( DWORD ) )
  817. {
  818. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid size for DWORD component" );
  819. DP8A_RETURN( DPNERR_INVALIDPARAM );
  820. }
  821. }
  822. else if( dwDataType == DPNA_DATATYPE_GUID )
  823. {
  824. if( dwComponentSize != sizeof( GUID ) )
  825. {
  826. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid size for GUID component" );
  827. DP8A_RETURN( DPNERR_INVALIDPARAM );
  828. }
  829. }
  830. #endif // !DPNBUILD_NOPARAMVAL
  831. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  832. if (dwDataType == DPNA_DATATYPE_STRING_ANSI)
  833. {
  834. WCHAR wszStackTemp[128];
  835. WCHAR * pwszTemp;
  836. // Allocate a buffer if the string is too large to convert in our
  837. // stack based buffer.
  838. if ((dwComponentSize * 2) > sizeof(wszStackTemp))
  839. {
  840. pwszTemp = (WCHAR*) DNMalloc(dwComponentSize * 2);
  841. if (pwszTemp == NULL)
  842. {
  843. DPFX(DPFPREP, 0, "Error allocating memory for conversion");
  844. DP8A_RETURN( DPNERR_OUTOFMEMORY );
  845. }
  846. }
  847. else
  848. {
  849. pwszTemp = wszStackTemp;
  850. }
  851. hr = STR_jkAnsiToWide(pwszTemp, (const char * const) pComponentData, dwComponentSize);
  852. if( FAILED( hr ) )
  853. {
  854. DPFX(DPFPREP, 0, "Error unable to convert element ANSI->Unicode 0x%x", hr );
  855. hr = DPNERR_CONVERSION;
  856. }
  857. else
  858. {
  859. DPFX(DPFPREP, DP8A_PARAMLEVEL, "Converted ANSI string pwszTag = 0x%p pComponentData = 0x%p dwComponentSize = %d",
  860. pwszTag, pwszTemp, (dwComponentSize * 2) );
  861. hr = pdp8Address->SetElement( pwszTag, pwszTemp, (dwComponentSize * 2), DPNA_DATATYPE_STRING );
  862. }
  863. if (pwszTemp != wszStackTemp)
  864. {
  865. DNFree(pwszTemp);
  866. pwszTemp = NULL;
  867. }
  868. }
  869. else
  870. {
  871. DPFX(DPFPREP, DP8A_PARAMLEVEL, "pwszTag = 0x%p pComponentData = 0x%p dwComponentSize = %d dwDataType = %d",
  872. pwszTag, pComponentData, dwComponentSize, dwDataType );
  873. hr = pdp8Address->SetElement( pwszTag, pComponentData, dwComponentSize, dwDataType );
  874. }
  875. DP8A_RETURN( hr );
  876. }
  877. #undef DPF_MODNAME
  878. #define DPF_MODNAME "DP8A_Clear"
  879. STDMETHODIMP DP8A_Clear( IDirectPlay8Address *pInterface )
  880. {
  881. HRESULT hr;
  882. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Enter" );
  883. #ifndef DPNBUILD_NOPARAMVAL
  884. if( pInterface == NULL ||
  885. !DP8A_VALID( pInterface ) )
  886. {
  887. DPFX(DPFPREP, DP8A_ENTERLEVEL, "Invalid object" );
  888. DP8A_RETURN( DPNERR_INVALIDOBJECT );
  889. }
  890. #endif // !DPNBUILD_NOPARAMVAL
  891. DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( pInterface );
  892. hr = pdp8Address->Clear( );
  893. DP8A_RETURN( hr );
  894. }
  895. #ifndef DPNBUILD_NOPARAMVAL
  896. BOOL IsValidDP8AObject( LPVOID lpvObject )
  897. #ifdef DPNBUILD_LIBINTERFACE
  898. {
  899. DP8ADDRESSOBJECT *pdp8Address = (DP8ADDRESSOBJECT *) lpvObject;
  900. if( pdp8Address == NULL ||
  901. !DNVALID_READPTR( pdp8Address, sizeof( DP8ADDRESSOBJECT ) ) )
  902. {
  903. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid object" );
  904. return FALSE;
  905. }
  906. #ifdef DPNBUILD_NOADDRESSIPINTERFACE
  907. if( pdp8Address->lpVtbl != &DP8A_BaseVtbl )
  908. #else // ! DPNBUILD_NOADDRESSIPINTERFACE
  909. if( pdp8Address->lpVtbl != &DP8A_BaseVtbl &&
  910. pdp8Address->lpVtbl != &DP8A_IPVtbl )
  911. #endif // ! DPNBUILD_NOADDRESSIPINTERFACE
  912. {
  913. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid object" );
  914. return FALSE;
  915. }
  916. return TRUE;
  917. }
  918. #else // ! DPNBUILD_LIBINTERFACE
  919. {
  920. INTERFACE_LIST *pIntList = (INTERFACE_LIST *) lpvObject;
  921. if( !DNVALID_READPTR( lpvObject, sizeof( INTERFACE_LIST ) ) )
  922. {
  923. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid object pointer" );
  924. return FALSE;
  925. }
  926. if( pIntList->lpVtbl != &DP8A_BaseVtbl &&
  927. #ifndef DPNBUILD_NOADDRESSIPINTERFACE
  928. pIntList->lpVtbl != &DP8A_IPVtbl &&
  929. #endif // ! DPNBUILD_NOADDRESSIPINTERFACE
  930. pIntList->lpVtbl != &DP8A_UnknownVtbl )
  931. {
  932. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid object" );
  933. return FALSE;
  934. }
  935. if( pIntList->iid != IID_IDirectPlay8Address &&
  936. #ifndef DPNBUILD_NOADDRESSIPINTERFACE
  937. pIntList->iid != IID_IDirectPlay8AddressIP &&
  938. #endif // ! DPNBUILD_NOADDRESSIPINTERFACE
  939. pIntList->iid != IID_IUnknown )
  940. {
  941. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Unknown object" );
  942. return FALSE;
  943. }
  944. if( pIntList->pObject == NULL ||
  945. !DNVALID_READPTR( pIntList->pObject, sizeof( OBJECT_DATA ) ) )
  946. {
  947. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid object" );
  948. return FALSE;
  949. }
  950. const DP8ADDRESSOBJECT *pdp8Address = (PDP8ADDRESSOBJECT) GET_OBJECT_FROM_INTERFACE( lpvObject );
  951. if( pdp8Address == NULL ||
  952. !DNVALID_READPTR( pdp8Address, sizeof( DP8ADDRESSOBJECT ) ) )
  953. {
  954. DPFX(DPFPREP, DP8A_ERRORLEVEL, "Invalid object" );
  955. return FALSE;
  956. }
  957. return TRUE;
  958. }
  959. #endif // ! DPNBUILD_LIBINTERFACE
  960. #endif // ! DPNBUILD_NOPARAMVAL