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.

811 lines
20 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: Unk.cpp
  6. * Content: IUnknown implementation
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 08/06/00 RichGr IA64: Use %p format specifier in DPFs for 32/64-bit pointers and handles.
  11. ***************************************************************************/
  12. #include "dnwsocki.h"
  13. #ifndef DPNBUILD_NOIPX
  14. #define DPN_REG_LOCAL_WSOCK_IPX_ROOT L"\\DPNSPWinsockIPX"
  15. #endif // ! DPNBUILD_NOIPX
  16. #ifndef DPNBUILD_NOIPV6
  17. #define DPN_REG_LOCAL_WSOCK_IPV6_ROOT L"\\DPNSPWinsockIPv6"
  18. #endif // ! DPNBUILD_NOIPV6
  19. #define DPN_REG_LOCAL_WSOCK_TCPIP_ROOT L"\\DPNSPWinsockTCP"
  20. #if ((! defined(WINCE)) && (! defined(_XBOX)))
  21. #define MAX_RESOURCE_STRING_LENGTH _MAX_PATH
  22. HRESULT LoadAndAllocString( UINT uiResourceID, wchar_t **lpswzString );
  23. #endif // ! WINCE and ! _XBOX
  24. #undef DPF_MODNAME
  25. #define DPF_MODNAME "DNWsockInit"
  26. BOOL DNWsockInit(HANDLE hModule)
  27. {
  28. DNASSERT( hModule != NULL );
  29. #ifdef _XBOX
  30. XDP8STARTUP_PARAMS * pStartupParams;
  31. XNetStartupParams xnsp;
  32. int iResult;
  33. //
  34. // The instance handle is actually a pointer to the startup parameters.
  35. //
  36. pStartupParams = (XDP8STARTUP_PARAMS*) hModule;
  37. //
  38. // Initialize the Xbox networking layer, unless we were forbidden.
  39. //
  40. if (! (pStartupParams->dwFlags & XDP8STARTUP_BYPASSXNETSTARTUP))
  41. {
  42. memset(&xnsp, 0, sizeof(xnsp));
  43. xnsp.cfgSizeOfStruct = sizeof(xnsp);
  44. #pragma TODO(vanceo, "Does this actually do anything?")
  45. if (pStartupParams->dwFlags & XDP8STARTUP_BYPASSSECURITY)
  46. {
  47. xnsp.cfgFlags |= XNET_STARTUP_BYPASS_SECURITY;
  48. }
  49. DPFX(DPFPREP, 1, "Initializing Xbox networking layer.");
  50. iResult = XNetStartup(&xnsp);
  51. if (iResult != 0)
  52. {
  53. DPFX(DPFPREP, 0, "Couldn't start XNet (err = %i)!", iResult);
  54. return FALSE;
  55. }
  56. g_fStartedXNet = TRUE;
  57. }
  58. #else // ! _XBOX
  59. #ifndef WINCE
  60. DNASSERT( g_hDLLInstance == NULL );
  61. g_hDLLInstance = (HINSTANCE) hModule;
  62. #endif // ! WINCE
  63. #endif // ! _XBOX
  64. //
  65. // attempt to initialize process-global items
  66. //
  67. if ( InitProcessGlobals() == FALSE )
  68. {
  69. DPFX(DPFPREP, 0, "Failed to initialize globals!" );
  70. #ifdef _XBOX
  71. if (g_fStartedXNet)
  72. {
  73. XNetCleanup();
  74. }
  75. #endif // _XBOX
  76. return FALSE;
  77. }
  78. #ifdef DPNBUILD_LIBINTERFACE
  79. //
  80. // Attempt to load Winsock.
  81. //
  82. if ( LoadWinsock() == FALSE )
  83. {
  84. DPFX(DPFPREP, 0, "Failed to load winsock!" );
  85. DeinitProcessGlobals();
  86. #ifdef _XBOX
  87. if (g_fStartedXNet)
  88. {
  89. XNetCleanup();
  90. }
  91. #endif // _XBOX
  92. return FALSE;
  93. }
  94. #endif // DPNBUILD_LIBINTERFACE
  95. #ifdef DPNBUILD_PREALLOCATEDMEMORYMODEL
  96. //
  97. // Pre-allocate a threadpool object.
  98. //
  99. if ( g_ThreadPoolPool.Preallocate( 1, NULL ) < 1 )
  100. {
  101. DPFX(DPFPREP, 0, "Failed to preallocate a threadpool object!" );
  102. #ifdef DPNBUILD_LIBINTERFACE
  103. UnloadWinsock();
  104. #endif // DPNBUILD_LIBINTERFACE
  105. DeinitProcessGlobals();
  106. #ifdef _XBOX
  107. if (g_fStartedXNet)
  108. {
  109. XNetCleanup();
  110. }
  111. #endif // _XBOX
  112. return FALSE;
  113. }
  114. #endif // DPNBUILD_PREALLOCATEDMEMORYMODEL
  115. return TRUE;
  116. }
  117. #undef DPF_MODNAME
  118. #define DPF_MODNAME "DNWsockDeInit"
  119. void DNWsockDeInit()
  120. {
  121. DPFX(DPFPREP, 5, "Deinitializing Wsock SP");
  122. #if ((! defined(WINCE)) && (! defined(_XBOX)))
  123. DNASSERT( g_hDLLInstance != NULL );
  124. g_hDLLInstance = NULL;
  125. #endif // ! WINCE and ! _XBOX
  126. #ifdef DPNBUILD_LIBINTERFACE
  127. //
  128. // Unload Winsock.
  129. //
  130. UnloadWinsock();
  131. #endif // DPNBUILD_LIBINTERFACE
  132. DeinitProcessGlobals();
  133. #ifdef _XBOX
  134. //
  135. // Clean up the Xbox networking layer if we started it.
  136. //
  137. if (g_fStartedXNet)
  138. {
  139. DPFX(DPFPREP, 1, "Cleaning up Xbox networking layer.");
  140. #ifdef DBG
  141. DNASSERT(XNetCleanup() == 0);
  142. #else // ! DBG
  143. XNetCleanup();
  144. #endif // ! DBG
  145. g_fStartedXNet = FALSE;
  146. }
  147. #endif // _XBOX
  148. }
  149. #ifndef DPNBUILD_NOCOMREGISTER
  150. #undef DPF_MODNAME
  151. #define DPF_MODNAME "DNWsockRegister"
  152. BOOL DNWsockRegister(LPCWSTR wszDLLName)
  153. {
  154. HRESULT hr = S_OK;
  155. BOOL fReturn = TRUE;
  156. CRegistry creg;
  157. #if ((! defined(WINCE)) && (! defined(_XBOX)))
  158. WCHAR *wszFriendlyName = NULL;
  159. #endif // ! WINCE and ! _XBOX
  160. #ifndef DPNBUILD_NOIPX
  161. if( !CRegistry::Register( L"DirectPlay8SPWSock.IPX.1", L"DirectPlay8 WSock IPX Provider Object",
  162. wszDLLName, &CLSID_DP8SP_IPX, L"DirectPlay8SPWSock.IPX") )
  163. {
  164. DPFERR( "Could not register dp8 IPX object" );
  165. fReturn = FALSE;
  166. }
  167. #endif // ! DPNBUILD_NOIPX
  168. if( !CRegistry::Register( L"DirectPlay8SPWSock.TCPIP.1", L"DirectPlay8 WSock TCPIP Provider Object",
  169. wszDLLName, &CLSID_DP8SP_TCPIP, L"DirectPlay8SPWSock.TCPIP") )
  170. {
  171. DPFERR( "Could not register dp8 IP object" );
  172. fReturn = FALSE;
  173. }
  174. #ifndef DPNBUILD_NOIPX
  175. if( !creg.Open( HKEY_LOCAL_MACHINE, DPN_REG_LOCAL_SP_SUBKEY DPN_REG_LOCAL_WSOCK_IPX_ROOT, FALSE, TRUE ) )
  176. {
  177. DPFERR( "Cannot create IPX sub-area!" );
  178. fReturn = FALSE;
  179. }
  180. else
  181. {
  182. #if ((! defined(WINCE)) && (! defined(_XBOX)))
  183. hr = LoadAndAllocString( IDS_FRIENDLYNAME_IPX, &wszFriendlyName );
  184. if( FAILED( hr ) )
  185. {
  186. DPFX(DPFPREP, 0, "Could not load IPX name! hr=0x%x", hr );
  187. fReturn = FALSE;
  188. }
  189. else
  190. {
  191. // Load from resource file
  192. creg.WriteString( DPN_REG_KEYNAME_FRIENDLY_NAME, wszFriendlyName );
  193. delete [] wszFriendlyName;
  194. creg.WriteGUID( DPN_REG_KEYNAME_GUID, CLSID_DP8SP_IPX );
  195. }
  196. #else // ! WINCE and ! _XBOX
  197. // Don't use the resource, just do it directly
  198. creg.WriteString( DPN_REG_KEYNAME_FRIENDLY_NAME, L"DirectPlay8 IPX Service Provider" );
  199. creg.WriteGUID( DPN_REG_KEYNAME_GUID, CLSID_DP8SP_IPX );
  200. #endif // ! WINCE and ! _XBOX
  201. creg.Close();
  202. }
  203. #endif // ! DPNBUILD_NOIPX
  204. if( !creg.Open( HKEY_LOCAL_MACHINE, DPN_REG_LOCAL_SP_SUBKEY DPN_REG_LOCAL_WSOCK_TCPIP_ROOT, FALSE, TRUE ) )
  205. {
  206. DPFERR( "Cannot create TCPIP sub-area!" );
  207. fReturn = FALSE;
  208. }
  209. else
  210. {
  211. #if ((! defined(WINCE)) && (! defined(_XBOX)))
  212. hr = LoadAndAllocString( IDS_FRIENDLYNAME_TCPIP, &wszFriendlyName );
  213. if( FAILED( hr ) )
  214. {
  215. DPFX(DPFPREP, 0, "Could not load IPX name! hr=0x%x", hr );
  216. fReturn = FALSE;
  217. }
  218. else
  219. {
  220. // Load from resource file
  221. creg.WriteString( DPN_REG_KEYNAME_FRIENDLY_NAME, wszFriendlyName );
  222. delete [] wszFriendlyName;
  223. creg.WriteGUID( DPN_REG_KEYNAME_GUID, CLSID_DP8SP_TCPIP );
  224. }
  225. #else // ! WINCE and ! _XBOX
  226. // Don't use the resource, just do it directly
  227. creg.WriteString( DPN_REG_KEYNAME_FRIENDLY_NAME, L"DirectPlay8 TCP/IP Service Provider" );
  228. creg.WriteGUID( DPN_REG_KEYNAME_GUID, CLSID_DP8SP_TCPIP );
  229. #endif // ! WINCE and ! _XBOX
  230. creg.Close();
  231. }
  232. return fReturn;
  233. }
  234. #undef DPF_MODNAME
  235. #define DPF_MODNAME "DNWsockUnRegister"
  236. BOOL DNWsockUnRegister()
  237. {
  238. HRESULT hr = S_OK;
  239. BOOL fReturn = TRUE;
  240. #ifndef DPNBUILD_NOIPX
  241. if( !CRegistry::UnRegister(&CLSID_DP8SP_IPX) )
  242. {
  243. DPFX(DPFPREP, 0, "Failed to unregister IPX object" );
  244. fReturn = FALSE;
  245. }
  246. #endif // ! DPNBUILD_NOIPX
  247. if( !CRegistry::UnRegister(&CLSID_DP8SP_TCPIP) )
  248. {
  249. DPFX(DPFPREP, 0, "Failed to unregister IP object" );
  250. fReturn = FALSE;
  251. }
  252. CRegistry creg;
  253. if( !creg.Open( HKEY_LOCAL_MACHINE, DPN_REG_LOCAL_SP_SUBKEY, FALSE, TRUE ) )
  254. {
  255. DPFERR( "Cannot remove app, does not exist" );
  256. }
  257. else
  258. {
  259. #ifndef DPNBUILD_NOIPX
  260. if( !creg.DeleteSubKey( &(DPN_REG_LOCAL_WSOCK_IPX_ROOT)[1] ) )
  261. {
  262. DPFERR( "Cannot remove IPX sub-key, could have elements" );
  263. }
  264. #endif // ! DPNBUILD_NOIPX
  265. #pragma TODO(vanceo, "Uncomment IPv6 when ready")
  266. /*
  267. #ifndef DPNBUILD_NOIPV6
  268. if( !creg.DeleteSubKey( &(DPN_REG_LOCAL_WSOCK_IPV6_ROOT)[1] ) )
  269. {
  270. DPFERR( "Cannot remove IPv6 sub-key, could have elements" );
  271. }
  272. #endif // ! DPNBUILD_NOIPV6
  273. */
  274. if( !creg.DeleteSubKey( &(DPN_REG_LOCAL_WSOCK_TCPIP_ROOT)[1] ) )
  275. {
  276. DPFERR( "Cannot remove TCPIP sub-key, could have elements" );
  277. }
  278. }
  279. return fReturn;
  280. }
  281. #endif // ! DPNBUILD_NOCOMREGISTER
  282. #ifndef DPNBUILD_LIBINTERFACE
  283. #undef DPF_MODNAME
  284. #define DPF_MODNAME "DNWsockGetRemainingObjectCount"
  285. DWORD DNWsockGetRemainingObjectCount()
  286. {
  287. return g_lOutstandingInterfaceCount;
  288. }
  289. #endif // ! DPNBUILD_LIBINTERFACE
  290. //**********************************************************************
  291. // Constant definitions
  292. //**********************************************************************
  293. #ifdef __MWERKS__
  294. #define EXP __declspec(dllexport)
  295. #else
  296. #define EXP
  297. #endif // __MWERKS__
  298. //**********************************************************************
  299. // Macro definitions
  300. //**********************************************************************
  301. //**********************************************************************
  302. // Structure definitions
  303. //**********************************************************************
  304. //**********************************************************************
  305. // Variable definitions
  306. //**********************************************************************
  307. //**********************************************************************
  308. // Function prototypes
  309. //**********************************************************************
  310. STDMETHODIMP DNSP_QueryInterface( IDP8ServiceProvider *lpDNSP, REFIID riid, LPVOID * ppvObj);
  311. #define NOTSUPPORTED(parm) (HRESULT (__stdcall *) (struct IDP8ServiceProvider *, parm)) DNSP_NotSupported
  312. //**********************************************************************
  313. // Function definitions
  314. //**********************************************************************
  315. // these are the vtables for the various WSock service providers One or the
  316. // other is used depending on what is passed to DoCreateInstance.
  317. #ifndef DPNBUILD_NOIPX
  318. static IDP8ServiceProviderVtbl ipxInterface =
  319. {
  320. DNSP_QueryInterface,
  321. DNSP_AddRef,
  322. DNSP_Release,
  323. DNSP_Initialize,
  324. DNSP_Close,
  325. DNSP_Connect,
  326. DNSP_Disconnect,
  327. DNSP_Listen,
  328. DNSP_SendData,
  329. DNSP_EnumQuery,
  330. DNSP_EnumRespond,
  331. DNSP_CancelCommand,
  332. NOTSUPPORTED(PSPENUMMULTICASTSCOPESDATA), // EnumMulticastScopes
  333. NOTSUPPORTED(PSPSHAREENDPOINTINFODATA), // ShareEndpointInfo
  334. NOTSUPPORTED(PSPGETENDPOINTBYADDRESSDATA), // GetEndpointByAddress
  335. DNSP_Update,
  336. DNSP_GetCaps,
  337. DNSP_SetCaps,
  338. DNSP_ReturnReceiveBuffers,
  339. DNSP_GetAddressInfo,
  340. #ifdef DPNBUILD_LIBINTERFACE
  341. NOTSUPPORTED(PSPISAPPLICATIONSUPPORTEDDATA), // IsApplicationSupported
  342. #else // ! DPNBUILD_LIBINTERFACE
  343. DNSP_IsApplicationSupported,
  344. #endif // ! DPNBUILD_LIBINTERFACE
  345. #ifdef DPNBUILD_ONLYONEADAPTER
  346. NOTSUPPORTED(PSPENUMADAPTERSDATA), // EnumAdapters
  347. #else // ! DPNBUILD_ONLYONEADAPTER
  348. DNSP_EnumAdapters,
  349. #endif // ! DPNBUILD_ONLYONEADAPTER
  350. #ifdef DPNBUILD_SINGLEPROCESS
  351. NOTSUPPORTED(PSPPROXYENUMQUERYDATA), // ProxyEnumQuery
  352. #else // ! DPNBUILD_SINGLEPROCESS
  353. DNSP_ProxyEnumQuery
  354. #endif // ! DPNBUILD_SINGLEPROCESS
  355. };
  356. #endif // DPNBUILD_NOIPX
  357. #ifndef DPNBUILD_NOIPV6
  358. static IDP8ServiceProviderVtbl ipv6Interface =
  359. {
  360. DNSP_QueryInterface,
  361. DNSP_AddRef,
  362. DNSP_Release,
  363. DNSP_Initialize,
  364. DNSP_Close,
  365. DNSP_Connect,
  366. DNSP_Disconnect,
  367. DNSP_Listen,
  368. DNSP_SendData,
  369. DNSP_EnumQuery,
  370. DNSP_EnumRespond,
  371. DNSP_CancelCommand,
  372. #ifdef DPNBUILD_NOMULTICAST
  373. NOTSUPPORTED(PSPENUMMULTICASTSCOPESDATA), // EnumMulticastScopes
  374. NOTSUPPORTED(PSPSHAREENDPOINTINFODATA), // ShareEndpointInfo
  375. NOTSUPPORTED(PSPGETENDPOINTBYADDRESSDATA), // GetEndpointByAddress
  376. #else // ! DPNBUILD_NOMULTICAST
  377. DNSP_EnumMulticastScopes,
  378. DNSP_ShareEndpointInfo,
  379. DNSP_GetEndpointByAddress,
  380. #endif // ! DPNBUILD_NOMULTICAST
  381. DNSP_Update,
  382. DNSP_GetCaps,
  383. DNSP_SetCaps,
  384. DNSP_ReturnReceiveBuffers,
  385. DNSP_GetAddressInfo,
  386. #ifdef DPNBUILD_LIBINTERFACE
  387. NOTSUPPORTED(PSPISAPPLICATIONSUPPORTEDDATA), // IsApplicationSupported
  388. #else // ! DPNBUILD_LIBINTERFACE
  389. DNSP_IsApplicationSupported,
  390. #endif // ! DPNBUILD_LIBINTERFACE
  391. #ifdef DPNBUILD_ONLYONEADAPTER
  392. NOTSUPPORTED(PSPENUMADAPTERSDATA), // EnumAdapters
  393. #else // ! DPNBUILD_ONLYONEADAPTER
  394. DNSP_EnumAdapters,
  395. #endif // ! DPNBUILD_ONLYONEADAPTER
  396. #ifdef DPNBUILD_SINGLEPROCESS
  397. NOTSUPPORTED(PSPPROXYENUMQUERYDATA), // ProxyEnumQuery
  398. #else // ! DPNBUILD_SINGLEPROCESS
  399. DNSP_ProxyEnumQuery
  400. #endif // ! DPNBUILD_SINGLEPROCESS
  401. };
  402. #endif // DPNBUILD_NOIPV6
  403. static IDP8ServiceProviderVtbl ipInterface =
  404. {
  405. DNSP_QueryInterface,
  406. DNSP_AddRef,
  407. DNSP_Release,
  408. DNSP_Initialize,
  409. DNSP_Close,
  410. DNSP_Connect,
  411. DNSP_Disconnect,
  412. DNSP_Listen,
  413. DNSP_SendData,
  414. DNSP_EnumQuery,
  415. DNSP_EnumRespond,
  416. DNSP_CancelCommand,
  417. #ifdef DPNBUILD_NOMULTICAST
  418. NOTSUPPORTED(PSPENUMMULTICASTSCOPESDATA), // EnumMulticastScopes
  419. NOTSUPPORTED(PSPSHAREENDPOINTINFODATA), // ShareEndpointInfo
  420. NOTSUPPORTED(PSPGETENDPOINTBYADDRESSDATA), // GetEndpointByAddress
  421. #else // ! DPNBUILD_NOMULTICAST
  422. DNSP_EnumMulticastScopes,
  423. DNSP_ShareEndpointInfo,
  424. DNSP_GetEndpointByAddress,
  425. #endif // ! DPNBUILD_NOMULTICAST
  426. DNSP_Update,
  427. DNSP_GetCaps,
  428. DNSP_SetCaps,
  429. DNSP_ReturnReceiveBuffers,
  430. DNSP_GetAddressInfo,
  431. #ifdef DPNBUILD_LIBINTERFACE
  432. NOTSUPPORTED(PSPISAPPLICATIONSUPPORTEDDATA), // IsApplicationSupported
  433. #else // ! DPNBUILD_LIBINTERFACE
  434. DNSP_IsApplicationSupported,
  435. #endif // ! DPNBUILD_LIBINTERFACE
  436. #ifdef DPNBUILD_ONLYONEADAPTER
  437. NOTSUPPORTED(PSPENUMADAPTERSDATA), // EnumAdapters
  438. #else // ! DPNBUILD_ONLYONEADAPTER
  439. DNSP_EnumAdapters,
  440. #endif // ! DPNBUILD_ONLYONEADAPTER
  441. #ifdef DPNBUILD_SINGLEPROCESS
  442. NOTSUPPORTED(PSPPROXYENUMQUERYDATA), // ProxyEnumQuery
  443. #else // ! DPNBUILD_SINGLEPROCESS
  444. DNSP_ProxyEnumQuery
  445. #endif // ! DPNBUILD_SINGLEPROCESS
  446. };
  447. //**********************************************************************
  448. // ------------------------------
  449. // DNSP_QueryInterface - query for interface
  450. //
  451. // Entry: Pointer to current interface
  452. // GUID of desired interface
  453. // Pointer to pointer to new interface
  454. //
  455. // Exit: Error code
  456. // ------------------------------
  457. #undef DPF_MODNAME
  458. #define DPF_MODNAME "DNSP_QueryInterface"
  459. STDMETHODIMP DNSP_QueryInterface( IDP8ServiceProvider *lpDNSP, REFIID riid, LPVOID * ppvObj)
  460. {
  461. HRESULT hr = S_OK;
  462. #ifndef DPNBUILD_LIBINTERFACE
  463. // hmmm, switch would be cleaner...
  464. if ((! IsEqualIID(riid, IID_IUnknown)) &&
  465. (! IsEqualIID(riid, IID_IDP8ServiceProvider)))
  466. {
  467. *ppvObj = NULL;
  468. hr = E_NOINTERFACE;
  469. }
  470. else
  471. #endif // ! DPNBUILD_LIBINTERFACE
  472. {
  473. #ifdef DPNBUILD_LIBINTERFACE
  474. DNASSERT(! "Querying SP interface when using DPNBUILD_LIBINTERFACE!");
  475. #endif // DPNBUILD_LIBINTERFACE
  476. *ppvObj = lpDNSP;
  477. DNSP_AddRef(lpDNSP);
  478. }
  479. return hr;
  480. }
  481. //**********************************************************************
  482. #ifndef DPNBUILD_NOIPX
  483. //**********************************************************************
  484. // ------------------------------
  485. // CreateIPXInterface - create an IPX interface
  486. //
  487. // Entry: Pointer to pointer to SP interface
  488. // Pointer to pointer to associated SP data
  489. //
  490. // Exit: Error code
  491. // ------------------------------
  492. #undef DPF_MODNAME
  493. #define DPF_MODNAME "CreateIPXInterface"
  494. #ifdef DPNBUILD_PREALLOCATEDMEMORYMODEL
  495. HRESULT CreateIPXInterface( const XDP8CREATE_PARAMS * const pDP8CreateParams, IDP8ServiceProvider **const ppiDP8SP )
  496. #else // ! DPNBUILD_PREALLOCATEDMEMORYMODEL
  497. HRESULT CreateIPXInterface( IDP8ServiceProvider **const ppiDP8SP )
  498. #endif // ! DPNBUILD_PREALLOCATEDMEMORYMODEL
  499. {
  500. HRESULT hr;
  501. CSPData *pSPData;
  502. DNASSERT( ppiDP8SP != NULL );
  503. //
  504. // initialize
  505. //
  506. hr = DPN_OK;
  507. pSPData = NULL;
  508. *ppiDP8SP = NULL;
  509. //
  510. // create main data class
  511. //
  512. hr = CreateSPData( &pSPData,
  513. AF_IPX,
  514. #ifdef DPNBUILD_PREALLOCATEDMEMORYMODEL
  515. pDP8CreateParams,
  516. #endif // DPNBUILD_PREALLOCATEDMEMORYMODEL
  517. &ipxInterface );
  518. if ( hr != DPN_OK )
  519. {
  520. DNASSERT( pSPData == NULL );
  521. DPFX(DPFPREP, 0, "Problem creating SPData!" );
  522. DisplayDNError( 0, hr );
  523. goto Failure;
  524. }
  525. DNASSERT( pSPData != NULL );
  526. *ppiDP8SP = pSPData->COMInterface();
  527. Exit:
  528. return hr;
  529. Failure:
  530. if ( pSPData != NULL )
  531. {
  532. pSPData->DecRef();
  533. pSPData = NULL;
  534. }
  535. goto Exit;
  536. }
  537. //**********************************************************************
  538. #endif // ! DPNBUILD_NOIPX
  539. //**********************************************************************
  540. // ------------------------------
  541. // CreateIPInterface - create an IP interface
  542. //
  543. // Entry: Pointer to pointer to SP interface
  544. //
  545. // Exit: Error code
  546. // ------------------------------
  547. #undef DPF_MODNAME
  548. #define DPF_MODNAME "CreateIPInterface"
  549. #ifdef DPNBUILD_PREALLOCATEDMEMORYMODEL
  550. HRESULT CreateIPInterface( const XDP8CREATE_PARAMS * const pDP8CreateParams, IDP8ServiceProvider **const ppiDP8SP )
  551. #else // ! DPNBUILD_PREALLOCATEDMEMORYMODEL
  552. HRESULT CreateIPInterface( IDP8ServiceProvider **const ppiDP8SP )
  553. #endif // ! DPNBUILD_PREALLOCATEDMEMORYMODEL
  554. {
  555. HRESULT hr;
  556. CSPData *pSPData;
  557. DNASSERT( ppiDP8SP != NULL );
  558. //
  559. // initialize
  560. //
  561. hr = DPN_OK;
  562. pSPData = NULL;
  563. *ppiDP8SP = NULL;
  564. //
  565. // create main data class
  566. //
  567. hr = CreateSPData( &pSPData,
  568. #if ((! defined(DPNBUILD_NOIPX)) || (! defined(DPNBUILD_NOIPV6)))
  569. AF_INET,
  570. #endif // ! DPNBUILD_NOIPX or ! DPNBUILD_NOIPV6
  571. #ifdef DPNBUILD_PREALLOCATEDMEMORYMODEL
  572. pDP8CreateParams,
  573. #endif // DPNBUILD_PREALLOCATEDMEMORYMODEL
  574. &ipInterface );
  575. if ( hr != DPN_OK )
  576. {
  577. DNASSERT( pSPData == NULL );
  578. DPFX(DPFPREP, 0, "Problem creating SPData!" );
  579. DisplayDNError( 0, hr );
  580. goto Failure;
  581. }
  582. DNASSERT( pSPData != NULL );
  583. *ppiDP8SP = pSPData->COMInterface();
  584. Exit:
  585. return hr;
  586. Failure:
  587. if ( pSPData != NULL )
  588. {
  589. pSPData->DecRef();
  590. pSPData = NULL;
  591. }
  592. goto Exit;
  593. }
  594. //**********************************************************************
  595. #ifndef DPNBUILD_LIBINTERFACE
  596. //**********************************************************************
  597. // ------------------------------
  598. // DoCreateInstance - create an instance of an interface
  599. //
  600. // Entry: Pointer to class factory
  601. // Pointer to unknown interface
  602. // Refernce of GUID of desired interface
  603. // Reference to another GUID?
  604. // Pointer to pointer to interface
  605. //
  606. // Exit: Error code
  607. // ------------------------------
  608. #undef DPF_MODNAME
  609. #define DPF_MODNAME "DoCreateInstance"
  610. HRESULT DoCreateInstance( LPCLASSFACTORY This,
  611. LPUNKNOWN pUnkOuter,
  612. REFCLSID rclsid,
  613. REFIID riid,
  614. LPVOID *ppvObj )
  615. {
  616. HRESULT hr;
  617. DNASSERT( ppvObj != NULL );
  618. //
  619. // initialize
  620. //
  621. *ppvObj = NULL;
  622. //
  623. // we can either create an IPX instance or an IP instance
  624. //
  625. if (IsEqualCLSID(rclsid, CLSID_DP8SP_TCPIP))
  626. {
  627. hr = CreateIPInterface( reinterpret_cast<IDP8ServiceProvider**>( ppvObj ) );
  628. }
  629. #ifndef DPNBUILD_NOIPX
  630. else if (IsEqualCLSID(rclsid, CLSID_DP8SP_IPX))
  631. {
  632. hr = CreateIPXInterface( reinterpret_cast<IDP8ServiceProvider**>( ppvObj ) );
  633. }
  634. #endif // ! DPNBUILD_NOIPX
  635. else
  636. {
  637. // this shouldn't happen if they called IClassFactory::CreateObject correctly
  638. DPFX(DPFPREP, 0, "Got unexpected CLSID!");
  639. hr = E_UNEXPECTED;
  640. }
  641. return hr;
  642. }
  643. //**********************************************************************
  644. #endif // ! DPNBUILD_LIBINTERFACE
  645. #if ((! defined(WINCE)) && (! defined(_XBOX)))
  646. #define MAX_RESOURCE_STRING_LENGTH _MAX_PATH
  647. #undef DPF_MODNAME
  648. #define DPF_MODNAME "LoadAndAllocString"
  649. HRESULT LoadAndAllocString( UINT uiResourceID, wchar_t **lpswzString )
  650. {
  651. int length;
  652. HRESULT hr;
  653. TCHAR szTmpBuffer[MAX_RESOURCE_STRING_LENGTH];
  654. length = LoadString( g_hDLLInstance, uiResourceID, szTmpBuffer, MAX_RESOURCE_STRING_LENGTH );
  655. if( length == 0 )
  656. {
  657. hr = GetLastError();
  658. DPFX(DPFPREP, 0, "Unable to load resource ID %d error 0x%x", uiResourceID, hr );
  659. *lpswzString = NULL;
  660. return DPNERR_GENERIC;
  661. }
  662. else
  663. {
  664. *lpswzString = new wchar_t[length+1];
  665. if( *lpswzString == NULL )
  666. {
  667. DPFX(DPFPREP, 0, "Alloc failure" );
  668. return DPNERR_OUTOFMEMORY;
  669. }
  670. #ifdef UNICODE
  671. wcscpy( *lpswzString, szTmpBuffer );
  672. #else // !UNICODE
  673. if( STR_jkAnsiToWide( *lpswzString, szTmpBuffer, length+1 ) != DPN_OK )
  674. {
  675. hr = GetLastError();
  676. delete[] *lpswzString;
  677. *lpswzString = NULL;
  678. DPFX(DPFPREP, 0, "Unable to upconvert from ansi to unicode hr=0x%x", hr );
  679. return DPNERR_GENERIC;
  680. }
  681. #endif // !UNICODE
  682. return DPN_OK;
  683. }
  684. }
  685. #endif // !WINCE and ! _XBOX