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.

930 lines
25 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // DataObj.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CDataObject class, which is the IDataObject
  10. // class used to transfer data between CluAdmin and the extension DLL
  11. // handlers.
  12. //
  13. // Author:
  14. // David Potter (davidp) June 4, 1996
  15. //
  16. // Revision History:
  17. //
  18. // Notes:
  19. //
  20. /////////////////////////////////////////////////////////////////////////////
  21. #include "stdafx.h"
  22. #include <CluAdmEx.h>
  23. #include "DataObj.h"
  24. #include "ClusItem.h"
  25. #include "ClusItem.inl"
  26. #include "Res.h"
  27. #include "resource.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Global Variables
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Object type map.
  37. static IDS g_rgidsObjectType[] =
  38. {
  39. NULL,
  40. IDS_ITEMTYPE_CLUSTER,
  41. IDS_ITEMTYPE_NODE,
  42. IDS_ITEMTYPE_GROUP,
  43. IDS_ITEMTYPE_RESOURCE,
  44. IDS_ITEMTYPE_RESTYPE,
  45. IDS_ITEMTYPE_NETWORK,
  46. IDS_ITEMTYPE_NETIFACE
  47. };
  48. #define RGIDS_OBJECT_TYPE_SIZE sizeof(g_rgidsObjectType) / sizeof(IDS)
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CDataObject
  51. /////////////////////////////////////////////////////////////////////////////
  52. IMPLEMENT_DYNAMIC(CDataObject, CObject)
  53. /////////////////////////////////////////////////////////////////////////////
  54. //++
  55. //
  56. // CDataObject::CDataObject
  57. //
  58. // Routine Description:
  59. // Default constructor.
  60. //
  61. // Arguments:
  62. // None.
  63. //
  64. // Return Value:
  65. // None.
  66. //
  67. //--
  68. /////////////////////////////////////////////////////////////////////////////
  69. CDataObject::CDataObject(void)
  70. {
  71. m_pci = NULL;
  72. m_lcid = NULL;
  73. m_hfont = NULL;
  74. m_hicon = NULL;
  75. m_pfGetResNetName = NULL;
  76. m_pModuleState = AfxGetModuleState();
  77. ASSERT(m_pModuleState != NULL);
  78. } //*** CDataObject::CDataObject
  79. /////////////////////////////////////////////////////////////////////////////
  80. //++
  81. //
  82. // CDataObject::~CDataObject
  83. //
  84. // Routine Description:
  85. // Destructor.
  86. //
  87. // Arguments:
  88. // None.
  89. //
  90. // Return Value:
  91. // None.
  92. //
  93. //--
  94. /////////////////////////////////////////////////////////////////////////////
  95. CDataObject::~CDataObject(void)
  96. {
  97. m_pModuleState = NULL;
  98. } //*** CDataObject::~CDataObject
  99. /////////////////////////////////////////////////////////////////////////////
  100. //++
  101. //
  102. // CDataObject::Init
  103. //
  104. // Routine Description:
  105. // Second-phase constructor.
  106. //
  107. // Arguments:
  108. // pci [IN OUT] Cluster item for which a property sheet is being displayed.
  109. // lcid [IN] Locale ID of resources to be loaded by extension.
  110. // hfont [IN] Font to use for property page text.
  111. // hicon [IN] Icon for upper left icon control.
  112. //
  113. // Return Value:
  114. // None.
  115. //
  116. //--
  117. /////////////////////////////////////////////////////////////////////////////
  118. void CDataObject::Init(
  119. IN OUT CClusterItem * pci,
  120. IN LCID lcid,
  121. IN HFONT hfont,
  122. IN HICON hicon
  123. )
  124. {
  125. ASSERT_VALID(pci);
  126. // Save parameters.
  127. m_pci = pci;
  128. m_lcid = lcid;
  129. m_hfont = hfont;
  130. m_hicon = hicon;
  131. } //*** CDataObject::Init
  132. /////////////////////////////////////////////////////////////////////////////
  133. //++
  134. //
  135. // CDataObject::InterfaceSupportsErrorInfo [ISupportsErrorInfo]
  136. //
  137. // Routine Description:
  138. // Determines whether the interface supports error info (???).
  139. //
  140. // Arguments:
  141. // riid [IN] Reference to the interface ID.
  142. //
  143. // Return Value:
  144. // S_OK Interface supports error info.
  145. // S_FALSE Interface does not support error info.
  146. //
  147. // Exceptions Thrown:
  148. // None.
  149. //
  150. //--
  151. /////////////////////////////////////////////////////////////////////////////
  152. STDMETHODIMP CDataObject::InterfaceSupportsErrorInfo(REFIID riid)
  153. {
  154. static const IID * rgiid[] =
  155. {
  156. &IID_IGetClusterDataInfo,
  157. &IID_IGetClusterObjectInfo,
  158. &IID_IGetClusterNodeInfo,
  159. &IID_IGetClusterGroupInfo,
  160. &IID_IGetClusterResourceInfo,
  161. };
  162. int iiid;
  163. HRESULT hr = S_FALSE;
  164. for (iiid = 0 ; iiid < sizeof(rgiid) / sizeof(rgiid[0]) ; iiid++)
  165. {
  166. if (InlineIsEqualGUID(*rgiid[iiid], riid))
  167. {
  168. hr = S_OK;
  169. }
  170. }
  171. return hr;
  172. } //*** CDataObject::InterfaceSupportsErrorInfo
  173. /////////////////////////////////////////////////////////////////////////////
  174. //++
  175. //
  176. // CDataObject::GetLocale [IGetClusterUIInfo]
  177. //
  178. // Routine Description:
  179. // Get the locale ID for the extension to use.
  180. //
  181. // Arguments:
  182. // None.
  183. //
  184. // Return Value:
  185. // LCID
  186. //
  187. //--
  188. /////////////////////////////////////////////////////////////////////////////
  189. STDMETHODIMP_(LCID) CDataObject::GetLocale(void)
  190. {
  191. return Lcid();
  192. } //*** CDataObject::GetLocale
  193. /////////////////////////////////////////////////////////////////////////////
  194. //++
  195. //
  196. // CDataObject::GetFont [IGetClusterUIInfo]
  197. //
  198. // Routine Description:
  199. // Get the font to use for property pages and wizard pages.
  200. //
  201. // Arguments:
  202. // None.
  203. //
  204. // Return Value:
  205. // HFONT
  206. //
  207. //--
  208. /////////////////////////////////////////////////////////////////////////////
  209. STDMETHODIMP_(HFONT) CDataObject::GetFont(void)
  210. {
  211. return Hfont();
  212. } //*** CDataObject::GetFont
  213. /////////////////////////////////////////////////////////////////////////////
  214. //++
  215. //
  216. // CDataObject::GetIcon [IGetClusterUIInfo]
  217. //
  218. // Routine Description:
  219. // Get the icon to use in the upper left corner of property pages
  220. // and wizard pages.
  221. //
  222. // Arguments:
  223. // None.
  224. //
  225. // Return Value:
  226. // HICON
  227. //
  228. //--
  229. /////////////////////////////////////////////////////////////////////////////
  230. STDMETHODIMP_(HICON) CDataObject::GetIcon(void)
  231. {
  232. return Hicon();
  233. } //*** CDataObject::GetIcon
  234. /////////////////////////////////////////////////////////////////////////////
  235. //++
  236. //
  237. // CDataObject::GetClusterName [IGetClusterDataInfo]
  238. //
  239. // Routine Description:
  240. // Get the name of the cluster in which this object exists.
  241. //
  242. // Arguments:
  243. // lpszName [OUT] String in which to return the name.
  244. // pcchName [IN OUT] Maximum length of lpszName buffer on
  245. // input. Set to the total number of characters
  246. // upon return, including terminating null character.
  247. // If no lpszName buffer is not specified, the
  248. // status returned will be NOERROR. If an lpszName
  249. // buffer is specified but it is too small, the
  250. // number of characters will be returned in pcchName
  251. // and an ERROR_MORE_DATA status will be returned.
  252. //
  253. // Return Value:
  254. // NOERROR Data (or size) copied successfully.
  255. // E_INVALIDARG Invalid arguments specified.
  256. // ERROR_MORE_DATA Buffer is too small.
  257. //
  258. //--
  259. /////////////////////////////////////////////////////////////////////////////
  260. STDMETHODIMP CDataObject::GetClusterName(
  261. OUT BSTR lpszName,
  262. IN OUT LONG * pcchName
  263. )
  264. {
  265. LONG cchName = 0;
  266. HRESULT hr = NOERROR;
  267. AFX_MANAGE_STATE(m_pModuleState);
  268. ASSERT_VALID(Pci());
  269. ASSERT_VALID(Pci()->Pdoc());
  270. // Validate parameters.
  271. if (pcchName == NULL)
  272. {
  273. hr = E_INVALIDARG;
  274. goto Cleanup;
  275. }
  276. try
  277. {
  278. // Save the length to copy.
  279. cchName = *pcchName;
  280. *pcchName = Pci()->Pdoc()->StrName().GetLength() + 1;
  281. } // try
  282. catch (...)
  283. {
  284. hr = E_INVALIDARG;
  285. goto Cleanup;
  286. } // catch: anything
  287. // If only the length is being requested, return it now.
  288. if (lpszName == NULL)
  289. {
  290. hr = NOERROR;
  291. goto Cleanup;
  292. }
  293. // If a buffer is specified and it is too small, return an error.
  294. if (cchName < *pcchName)
  295. {
  296. hr = ERROR_MORE_DATA;
  297. goto Cleanup;
  298. }
  299. // Copy the data.
  300. hr = StringCchCopyNW( lpszName, cchName, Pci()->Pdoc()->StrName(), Pci()->Pdoc()->StrName().GetLength() );
  301. if ( FAILED( hr ) )
  302. {
  303. goto Cleanup;
  304. }
  305. Cleanup:
  306. return hr;
  307. } //*** CDataObject::GetClusterName
  308. /////////////////////////////////////////////////////////////////////////////
  309. //++
  310. //
  311. // CDataObject::GetClusterHandle [IGetClusterDataInfo]
  312. //
  313. // Routine Description:
  314. // Get the cluster handle for these objects.
  315. //
  316. // Arguments:
  317. // None.
  318. //
  319. // Return Value:
  320. // HCLUSTER
  321. //
  322. //--
  323. /////////////////////////////////////////////////////////////////////////////
  324. STDMETHODIMP_(HCLUSTER) CDataObject::GetClusterHandle(void)
  325. {
  326. AFX_MANAGE_STATE(m_pModuleState);
  327. ASSERT_VALID(Pci());
  328. return Pci()->Hcluster();
  329. } //*** CDataObject::GetClusterHandle
  330. /////////////////////////////////////////////////////////////////////////////
  331. //++
  332. //
  333. // CDataObject::GetObjectCount [IGetClusterDataInfo]
  334. //
  335. // Routine Description:
  336. // Get the number of selected objects.
  337. //
  338. // Arguments:
  339. // None.
  340. //
  341. // Return Value:
  342. // cObj
  343. //
  344. //--
  345. /////////////////////////////////////////////////////////////////////////////
  346. STDMETHODIMP_(LONG) CDataObject::GetObjectCount(void)
  347. {
  348. // We only support one selected object at a time for now.
  349. return 1;
  350. } //*** CDataObject::GetObjectCount
  351. /////////////////////////////////////////////////////////////////////////////
  352. //++
  353. //
  354. // CDataObject::GetObjectName [IGetClusterObjectInfo]
  355. //
  356. // Routine Description:
  357. // Get the name of the specified object.
  358. //
  359. // Arguments:
  360. // lObjIndex [IN] Zero-based index of the object.
  361. // lpszName [OUT] String in which to return the name.
  362. // pcchName [IN OUT] Maximum length of lpszName buffer on
  363. // input. Set to the total number of characters
  364. // upon return, including terminating null character.
  365. // If no lpszName buffer is not specified, the
  366. // status returned will be NOERROR. If an lpszName
  367. // buffer is specified but it is too small, the
  368. // number of characters will be returned in pcchName
  369. // and an ERROR_MORE_DATA status will be returned.
  370. //
  371. // Return Value:
  372. // NOERROR Data (or size) copied successfully.
  373. // E_INVALIDARG Invalid arguments specified.
  374. // ERROR_MORE_DATA Buffer is too small.
  375. //
  376. //--
  377. /////////////////////////////////////////////////////////////////////////////
  378. STDMETHODIMP CDataObject::GetObjectName(
  379. IN LONG lObjIndex,
  380. OUT BSTR lpszName,
  381. IN OUT LONG * pcchName
  382. )
  383. {
  384. LONG cchName = 0;
  385. HRESULT hr = NOERROR;
  386. AFX_MANAGE_STATE(m_pModuleState);
  387. ASSERT_VALID(Pci());
  388. // Validate parameters.
  389. // We only support one selected object at a time for now.
  390. if ((lObjIndex != 0) || (pcchName == NULL))
  391. {
  392. hr = E_INVALIDARG;
  393. goto Cleanup;
  394. }
  395. // Save the length to copy.
  396. try
  397. {
  398. cchName = *pcchName;
  399. *pcchName = Pci()->StrName().GetLength() + 1;
  400. } // try
  401. catch (...)
  402. {
  403. hr = E_INVALIDARG;
  404. goto Cleanup;
  405. } // catch: anything
  406. // If only the length is being requested, return it now.
  407. if (lpszName == NULL)
  408. {
  409. hr = NOERROR;
  410. goto Cleanup;
  411. }
  412. // If a buffer is specified and it is too small, return an error.
  413. if (cchName < *pcchName)
  414. {
  415. hr = ERROR_MORE_DATA;
  416. goto Cleanup;
  417. }
  418. // Copy the data.
  419. hr = StringCchCopyNW( lpszName, cchName, Pci()->StrName(), Pci()->StrName().GetLength() );
  420. if ( FAILED( hr ) )
  421. {
  422. goto Cleanup;
  423. }
  424. Cleanup:
  425. return hr;
  426. } //*** CDataObject::GetObjectName
  427. /////////////////////////////////////////////////////////////////////////////
  428. //++
  429. //
  430. // CDataObject::GetObjectType [IGetClusterObjectInfo]
  431. //
  432. // Routine Description:
  433. // Get the cluster database registry key for the specified object.
  434. //
  435. // Arguments:
  436. // lObjIndex [IN] Zero-based index of the object.
  437. //
  438. // Return Value:
  439. // -1 Invalid argument. Call GetLastError for more information.
  440. // CLUADMEX_OBJECT_TYPE
  441. //
  442. //--
  443. /////////////////////////////////////////////////////////////////////////////
  444. STDMETHODIMP_(CLUADMEX_OBJECT_TYPE) CDataObject::GetObjectType(
  445. IN LONG lObjIndex
  446. )
  447. {
  448. int iids;
  449. CLUADMEX_OBJECT_TYPE cot = CLUADMEX_OT_NONE;
  450. AFX_MANAGE_STATE(m_pModuleState);
  451. ASSERT_VALID(Pci());
  452. // Validate parameters.
  453. // We only support one selected object at a time for now.
  454. if (lObjIndex != 0)
  455. {
  456. SetLastError((DWORD) E_INVALIDARG);
  457. cot = (CLUADMEX_OBJECT_TYPE) -1;
  458. goto Cleanup;
  459. } // if: invalid argument
  460. // Get the object type.
  461. for (iids = 0 ; iids < RGIDS_OBJECT_TYPE_SIZE ; iids++)
  462. {
  463. if (g_rgidsObjectType[iids] == Pci()->IdsType())
  464. {
  465. cot = (CLUADMEX_OBJECT_TYPE) iids;
  466. break;
  467. }
  468. } // for: each entry in the table
  469. Cleanup:
  470. return cot;
  471. } //*** CDataObject::GetObjectType
  472. /////////////////////////////////////////////////////////////////////////////
  473. //++
  474. //
  475. // CDataObject::GetNodeHandle [IGetClusterNodeInfo]
  476. //
  477. // Routine Description:
  478. // Get the handle for the specified node.
  479. //
  480. // Arguments:
  481. // lObjIndex [IN] Zero-based index of the object.
  482. //
  483. // Return Value:
  484. // HNODE
  485. //
  486. //--
  487. /////////////////////////////////////////////////////////////////////////////
  488. STDMETHODIMP_(HNODE) CDataObject::GetNodeHandle(
  489. IN LONG lObjIndex
  490. )
  491. {
  492. CClusterNode * pciNode = (CClusterNode *) Pci();
  493. HNODE hnode = NULL;
  494. AFX_MANAGE_STATE(m_pModuleState);
  495. ASSERT_VALID(Pci());
  496. // Validate parameters.
  497. // We only support one selected object at a time for now.
  498. if ( (lObjIndex != 0)
  499. || (Pci()->IdsType() != IDS_ITEMTYPE_NODE))
  500. {
  501. SetLastError((DWORD) E_INVALIDARG);
  502. goto Cleanup;
  503. } // if: invalid argument
  504. ASSERT_KINDOF(CClusterNode, pciNode);
  505. hnode = pciNode->Hnode();
  506. Cleanup:
  507. return hnode;
  508. } //*** CDataObject::GetNodeHandle
  509. /////////////////////////////////////////////////////////////////////////////
  510. //++
  511. //
  512. // CDataObject::GetGroupHandle [IGetClusterGroupInfo]
  513. //
  514. // Routine Description:
  515. // Get the handle for the specified group.
  516. //
  517. // Arguments:
  518. // lObjIndex [IN] Zero-based index of the object.
  519. //
  520. // Return Value:
  521. // HGROUP
  522. //
  523. //--
  524. /////////////////////////////////////////////////////////////////////////////
  525. STDMETHODIMP_(HGROUP) CDataObject::GetGroupHandle(
  526. IN LONG lObjIndex
  527. )
  528. {
  529. CGroup * pciGroup = (CGroup *) Pci();
  530. HGROUP hgroup = NULL;
  531. AFX_MANAGE_STATE(m_pModuleState);
  532. ASSERT_VALID(Pci());
  533. // Validate parameters.
  534. // We only support one selected object at a time for now.
  535. if ( (lObjIndex != 0)
  536. || (Pci()->IdsType() != IDS_ITEMTYPE_GROUP))
  537. {
  538. SetLastError((DWORD) E_INVALIDARG);
  539. goto Cleanup;
  540. } // if: invalid argument
  541. ASSERT_KINDOF(CGroup, pciGroup);
  542. hgroup = pciGroup->Hgroup();
  543. Cleanup:
  544. return hgroup;
  545. } //*** CDataObject::GetGroupHandle
  546. /////////////////////////////////////////////////////////////////////////////
  547. //++
  548. //
  549. // CDataObject::GetResourceHandle [IGetClusterResourceInfo]
  550. //
  551. // Routine Description:
  552. // Get the handle for the specified resource.
  553. //
  554. // Arguments:
  555. // lObjIndex [IN] Zero-based index of the object.
  556. //
  557. // Return Value:
  558. // HRESOURCE
  559. //
  560. //--
  561. /////////////////////////////////////////////////////////////////////////////
  562. STDMETHODIMP_(HRESOURCE) CDataObject::GetResourceHandle(
  563. IN LONG lObjIndex
  564. )
  565. {
  566. CResource * pciRes = (CResource *) Pci();
  567. HRESOURCE hres = NULL;
  568. AFX_MANAGE_STATE(m_pModuleState);
  569. ASSERT_VALID(Pci());
  570. // Validate parameters.
  571. // We only support one selected object at a time for now.
  572. if ( (lObjIndex != 0)
  573. || (Pci()->IdsType() != IDS_ITEMTYPE_RESOURCE))
  574. {
  575. SetLastError((DWORD) E_INVALIDARG);
  576. goto Cleanup;
  577. } // if: invalid argument
  578. ASSERT_KINDOF(CResource, pciRes);
  579. hres = pciRes->Hresource();
  580. Cleanup:
  581. return hres;
  582. } //*** CDataObject::GetResourceHandle
  583. /////////////////////////////////////////////////////////////////////////////
  584. //++
  585. //
  586. // CDataObject::GetResourceTypeName [IGetClusterResourceInfo]
  587. //
  588. // Routine Description:
  589. // Returns the name of the resource type of the specified resource.
  590. //
  591. // Arguments:
  592. // lObjIndex [IN] Zero-based index of the object.
  593. // lpszResTypeName [OUT] String in which to return the resource type name.
  594. // pcchResTypeName [IN OUT] Maximum length of lpszResTypeName buffer on
  595. // input. Set to the total number of characters
  596. // upon return, including terminating null character.
  597. // If no lpszResTypeName buffer is not specified, the
  598. // status returned will be NOERROR. If an lpszResTypeName
  599. // buffer is specified but it is too small, the
  600. // number of characters will be returned in pcchResTypeName
  601. // and an ERROR_MORE_DATA status will be returned.
  602. //
  603. // Return Value:
  604. // NOERROR Data (or size) copied successfully.
  605. // E_INVALIDARG Invalid arguments specified.
  606. // ERROR_MORE_DATA Buffer is too small.
  607. //
  608. //--
  609. /////////////////////////////////////////////////////////////////////////////
  610. STDMETHODIMP CDataObject::GetResourceTypeName(
  611. IN LONG lObjIndex,
  612. OUT BSTR lpszResTypeName,
  613. IN OUT LONG * pcchResTypeName
  614. )
  615. {
  616. LONG cchResTypeName = 0;
  617. CResource * pciRes = (CResource *) Pci();
  618. CString const * pstrResourceTypeName;
  619. HRESULT hr = NOERROR;
  620. AFX_MANAGE_STATE(m_pModuleState);
  621. ASSERT_VALID(Pci());
  622. // Validate parameters.
  623. // We only support one selected object at a time for now.
  624. if ((lObjIndex != 0)
  625. || (pcchResTypeName == NULL)
  626. || (Pci()->IdsType() != IDS_ITEMTYPE_RESOURCE))
  627. {
  628. hr = E_INVALIDARG;
  629. goto Cleanup;
  630. } // if: invalid argument
  631. ASSERT_KINDOF(CResource, pciRes);
  632. // Get a pointer to the name to copy.
  633. if (pciRes->PciResourceType() != NULL)
  634. {
  635. ASSERT_VALID(pciRes->PciResourceType());
  636. pstrResourceTypeName = &pciRes->PciResourceType()->StrName();
  637. } // if: valid resource type pointer
  638. else
  639. pstrResourceTypeName = &pciRes->StrResourceType();
  640. // Save the length to copy.
  641. try
  642. {
  643. cchResTypeName = *pcchResTypeName;
  644. *pcchResTypeName = pstrResourceTypeName->GetLength() + 1;
  645. } // try
  646. catch (...)
  647. {
  648. hr = E_INVALIDARG;
  649. goto Cleanup;
  650. } // catch: anything
  651. // If only the length is being requested, return it now.
  652. if (lpszResTypeName == NULL)
  653. {
  654. hr = NOERROR;
  655. goto Cleanup;
  656. }
  657. // If a buffer is specified and it is too small, return an error.
  658. if (cchResTypeName < *pcchResTypeName)
  659. {
  660. hr = ERROR_MORE_DATA;
  661. goto Cleanup;
  662. }
  663. // Copy the data.
  664. hr = StringCchCopyNW(lpszResTypeName, cchResTypeName, *pstrResourceTypeName, pstrResourceTypeName->GetLength() );
  665. if ( FAILED( hr ) )
  666. {
  667. goto Cleanup;
  668. }
  669. Cleanup:
  670. return hr;
  671. } //*** CDataObject::GetResourceTypeName
  672. /////////////////////////////////////////////////////////////////////////////
  673. //++
  674. //
  675. // CDataObject::GetResourceNetworkName [IGetClusterResourceInfo]
  676. //
  677. // Routine Description:
  678. // Returns the name of the network name of the first Network Name
  679. // resource on which the specified resource depends.
  680. //
  681. // Arguments:
  682. // lObjIndex [IN] Zero-based index of the object.
  683. // lpszNetName [OUT] String in which to return the network name.
  684. // pcchNetName [IN OUT] Points to a variable that specifies the
  685. // maximum size, in characters, of the buffer. This
  686. // value should be large enough to contain
  687. // MAX_COMPUTERNAME_LENGTH + 1 characters. Upon
  688. // return it contains the actual number of characters
  689. // copied.
  690. //
  691. // Return Value:
  692. // TRUE Data (or size) copied successfully.
  693. // FALSE Error getting information. GetLastError() returns:
  694. // E_INVALIDARG Invalid arguments specified.
  695. //
  696. //--
  697. /////////////////////////////////////////////////////////////////////////////
  698. STDMETHODIMP_(BOOL) CDataObject::GetResourceNetworkName(
  699. IN LONG lObjIndex,
  700. OUT BSTR lpszNetName,
  701. IN OUT ULONG * pcchNetName
  702. )
  703. {
  704. BOOL bSuccess = FALSE;
  705. CResource * pciRes = (CResource *) Pci();
  706. AFX_MANAGE_STATE(m_pModuleState);
  707. ASSERT_VALID(Pci());
  708. try
  709. {
  710. // Validate parameters.
  711. // We only support one selected object at a time for now.
  712. if ((lObjIndex != 0)
  713. || (pcchNetName == NULL)
  714. || (*pcchNetName < MAX_COMPUTERNAME_LENGTH)
  715. || (Pci()->IdsType() != IDS_ITEMTYPE_RESOURCE))
  716. {
  717. SetLastError((DWORD) E_INVALIDARG);
  718. goto Cleanup;
  719. } // if: invalid argument
  720. ASSERT_KINDOF(CResource, pciRes);
  721. // If there is a function for getting this information, call it.
  722. // Otherwise, handle it ourselves.
  723. if (PfGetResNetName() != NULL)
  724. {
  725. bSuccess = (*PfGetResNetName())(lpszNetName, pcchNetName, m_pvGetResNetNameContext);
  726. }
  727. else
  728. {
  729. bSuccess = pciRes->BGetNetworkName(lpszNetName, pcchNetName);
  730. }
  731. } // try
  732. catch (...)
  733. {
  734. bSuccess = FALSE;
  735. SetLastError((DWORD) E_INVALIDARG);
  736. } // catch: anything
  737. Cleanup:
  738. return bSuccess;
  739. } //*** CDataObject::GetResourceNetworkName
  740. /////////////////////////////////////////////////////////////////////////////
  741. //++
  742. //
  743. // CDataObject::GetNetworkHandle [IGetClusterNetworkInfo]
  744. //
  745. // Routine Description:
  746. // Get the handle for the specified network.
  747. //
  748. // Arguments:
  749. // lObjIndex [IN] Zero-based index of the object.
  750. //
  751. // Return Value:
  752. // HNETWORK
  753. //
  754. //--
  755. /////////////////////////////////////////////////////////////////////////////
  756. STDMETHODIMP_(HNETWORK) CDataObject::GetNetworkHandle(
  757. IN LONG lObjIndex
  758. )
  759. {
  760. CNetwork * pciNetwork = (CNetwork *) Pci();
  761. HNETWORK hnet = NULL;
  762. AFX_MANAGE_STATE(m_pModuleState);
  763. ASSERT_VALID(Pci());
  764. // Validate parameters.
  765. // We only support one selected object at a time for now.
  766. if ( (lObjIndex != 0)
  767. || (Pci()->IdsType() != IDS_ITEMTYPE_NETWORK))
  768. {
  769. SetLastError((DWORD) E_INVALIDARG);
  770. goto Cleanup;
  771. } // if: invalid argument
  772. ASSERT_KINDOF(CNetwork, pciNetwork);
  773. hnet = pciNetwork->Hnetwork();
  774. Cleanup:
  775. return hnet;
  776. } //*** CDataObject::GetNetworkHandle
  777. /////////////////////////////////////////////////////////////////////////////
  778. //++
  779. //
  780. // CDataObject::GetNetInterfaceHandle [IGetClusterNetInterfaceInfo]
  781. //
  782. // Routine Description:
  783. // Get the handle for the specified network interface.
  784. //
  785. // Arguments:
  786. // lObjIndex [IN] Zero-based index of the object.
  787. //
  788. // Return Value:
  789. // HNETINTERFACE
  790. //
  791. //--
  792. /////////////////////////////////////////////////////////////////////////////
  793. STDMETHODIMP_(HNETINTERFACE) CDataObject::GetNetInterfaceHandle(
  794. IN LONG lObjIndex
  795. )
  796. {
  797. CNetInterface * pciNetIFace = (CNetInterface *) Pci();
  798. HNETINTERFACE hnetiface = NULL;
  799. AFX_MANAGE_STATE(m_pModuleState);
  800. ASSERT_VALID(Pci());
  801. // Validate parameters.
  802. // We only support one selected object at a time for now.
  803. if ( (lObjIndex != 0)
  804. || (Pci()->IdsType() != IDS_ITEMTYPE_NETIFACE))
  805. {
  806. SetLastError((DWORD) E_INVALIDARG);
  807. goto Cleanup;
  808. } // if: invalid argument
  809. ASSERT_KINDOF(CNetwork, pciNetIFace);
  810. hnetiface = pciNetIFace->Hnetiface();
  811. Cleanup:
  812. return hnetiface;
  813. } //*** CDataObject::GetNetInterfaceHandle