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.

952 lines
27 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1997.
  5. //
  6. // File: epoptppg.cpp
  7. //
  8. // Contents: Implements the classes CRpcOptionsPropertyPage
  9. //
  10. // Classes:
  11. //
  12. // Methods: CRpcOptionsPropertyPage::CRpcOptionsPropertyPage
  13. // CRpcOptionsPropertyPage::~CRpcOptionsPropertyPage
  14. //
  15. // History: 02-Dec-96 RonanS Created.
  16. //
  17. //----------------------------------------------------------------------
  18. #include "stdafx.h"
  19. #include "olecnfg.h"
  20. #include "resource.h"
  21. #include "Epoptppg.h"
  22. #include "Epprops.h"
  23. #include "TChar.h"
  24. #include "util.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CRpcOptionsPropertyPage property page
  32. IMPLEMENT_DYNCREATE(CRpcOptionsPropertyPage, CPropertyPage)
  33. //+-------------------------------------------------------------------------
  34. //
  35. // Member: CRpcOptionsPropertyPage::CRpcOptionsPropertyPage
  36. //
  37. // Synopsis: Constructor
  38. //
  39. // Arguments: None
  40. //
  41. // Returns: Nothing
  42. //
  43. // Algorithm: N/A
  44. //
  45. // History: 02-Dec-96 Ronans Created
  46. //
  47. //--------------------------------------------------------------------------
  48. CRpcOptionsPropertyPage::CRpcOptionsPropertyPage() : CPropertyPage(CRpcOptionsPropertyPage::IDD)
  49. {
  50. //{{AFX_DATA_INIT(CRpcOptionsPropertyPage)
  51. //}}AFX_DATA_INIT
  52. m_bChanged = FALSE;
  53. // make distinguished ednpoint data description for default settings
  54. m_epSysDefault = new CEndpointData;
  55. m_nSelected = -1;
  56. }
  57. //+-------------------------------------------------------------------------
  58. //
  59. // Member: CRpcOptionsPropertyPage::~CRpcOptionsPropertyPage
  60. //
  61. // Synopsis: Destructor
  62. //
  63. // Arguments: None
  64. //
  65. // Returns: Nothing
  66. //
  67. // Algorithm: N/A
  68. //
  69. // History: 02-Dec-96 Ronans Created
  70. //
  71. //--------------------------------------------------------------------------
  72. CRpcOptionsPropertyPage::~CRpcOptionsPropertyPage()
  73. {
  74. ClearProtocols();
  75. // remove distinguished default settings descriptor
  76. if (m_epSysDefault)
  77. delete m_epSysDefault;
  78. }
  79. //+-------------------------------------------------------------------------
  80. //
  81. // Member: CRpcOptionsPropertyPage::DoDataExchange
  82. //
  83. // Synopsis: Standard method for dialog data exchange. MFC uses this to
  84. // transfer data between the controls and the C++ classes memeber variables.
  85. //
  86. // Arguments: None
  87. //
  88. // Returns: Nothing
  89. //
  90. // Algorithm: N/A
  91. //
  92. // History: 02-Dec-96 Ronans Created
  93. //
  94. //--------------------------------------------------------------------------
  95. void CRpcOptionsPropertyPage::DoDataExchange(CDataExchange* pDX)
  96. {
  97. CPropertyPage::DoDataExchange(pDX);
  98. //{{AFX_DATA_MAP(CRpcOptionsPropertyPage)
  99. DDX_Control(pDX, IDC_LSTPROTSEQ, m_lstProtseqs);
  100. DDX_Control(pDX, IDC_CMDUPDATE, m_btnUpdate);
  101. DDX_Control(pDX, IDC_CMDREMOVE, m_btnRemove);
  102. DDX_Control(pDX, IDC_CMDCLEAR, m_btnClear);
  103. DDX_Control(pDX, IDC_CMDADD, m_btnAdd);
  104. //}}AFX_DATA_MAP
  105. }
  106. BEGIN_MESSAGE_MAP(CRpcOptionsPropertyPage, CPropertyPage)
  107. //{{AFX_MSG_MAP(CRpcOptionsPropertyPage)
  108. ON_BN_CLICKED(IDC_CMDCLEAR, OnClearEndpoints)
  109. ON_BN_CLICKED(IDC_CMDREMOVE, OnRemoveEndpoint)
  110. ON_BN_CLICKED(IDC_CMDUPDATE, OnUpdateEndpoint)
  111. ON_BN_CLICKED(IDC_CMDADD, OnAddEndpoint)
  112. ON_NOTIFY(NM_CLICK, IDC_LSTPROTSEQ, OnSelectProtseq)
  113. ON_WM_SETFOCUS()
  114. ON_WM_KILLFOCUS()
  115. ON_WM_HELPINFO()
  116. ON_NOTIFY(NM_DBLCLK, IDC_LSTPROTSEQ, OnPropertiesProtseq)
  117. //}}AFX_MSG_MAP
  118. END_MESSAGE_MAP()
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CRpcOptionsPropertyPage message handlers
  121. //+-------------------------------------------------------------------------
  122. //
  123. // Member: CRpcOptionsPropertyPage::OnInitDialog
  124. //
  125. // Synopsis: This standard MFC method will be called when the dialog is to be initialised.
  126. // It is called when the WIN32 Window object receives a WM_INITDIALOG message.
  127. //
  128. // Arguments: None
  129. //
  130. // Returns: Nothing
  131. //
  132. // Algorithm: N/A
  133. //
  134. // History: 02-Dec-96 Ronans Created
  135. //
  136. //--------------------------------------------------------------------------
  137. BOOL CRpcOptionsPropertyPage::OnInitDialog()
  138. {
  139. CPropertyPage::OnInitDialog();
  140. // setup image list control for dialog (for use with listview)
  141. m_imgNetwork.Create( IDB_IMGNETWORK, 16, 0, RGB(255,255,255));
  142. m_lstProtseqs.SetImageList(&m_imgNetwork, LVSIL_SMALL);
  143. ASSERT(m_imgNetwork.GetImageCount() == 2);
  144. RefreshEPList();
  145. return TRUE; // return TRUE unless you set the focus to a control
  146. }
  147. const TCHAR szEndpointText[] = TEXT("Endpoint");
  148. const int lenEndpoint = (sizeof(szEndpointText) / sizeof(TCHAR)) -1;
  149. //+-------------------------------------------------------------------------
  150. //
  151. // Member: CRpcOptionsPropertyPage::InitData
  152. //
  153. // Synopsis: Method to initialise options
  154. //
  155. // Arguments: None
  156. //
  157. // Returns: Nothing
  158. //
  159. // Algorithm: N/A
  160. //
  161. // History: 02-Dec-96 Ronans Created
  162. //
  163. //--------------------------------------------------------------------------
  164. void CRpcOptionsPropertyPage::InitData(CString AppName, HKEY hkAppID)
  165. {
  166. // read DCOM endpoint data from the registry
  167. ASSERT(hkAppID != NULL);
  168. HKEY hkEndpoints = NULL;
  169. DWORD dwType = REG_MULTI_SZ;
  170. // try to allocate a buffer.
  171. LONG lErr = ERROR_OUTOFMEMORY;
  172. DWORD dwcbBuffer = 1024 * sizeof(TCHAR);
  173. TCHAR* pszBuffer = new TCHAR[1024];
  174. ASSERT(pszBuffer != NULL);
  175. if (pszBuffer)
  176. {
  177. // try to read values into default sized buffer
  178. lErr = RegQueryValueEx(hkAppID,
  179. TEXT("Endpoints"),
  180. 0,
  181. &dwType,
  182. (LPBYTE)pszBuffer,
  183. &dwcbBuffer);
  184. // if buffer is not big enough, extend it and reread
  185. if (lErr == ERROR_MORE_DATA)
  186. {
  187. delete pszBuffer;
  188. lErr = ERROR_OUTOFMEMORY;
  189. pszBuffer = new TCHAR[(dwcbBuffer/sizeof(TCHAR)) + 1];
  190. if (pszBuffer)
  191. {
  192. lErr = RegQueryValueEx(hkAppID,
  193. TEXT("Endpoints"),
  194. 0,
  195. &dwType,
  196. (LPBYTE)pszBuffer,
  197. &dwcbBuffer);
  198. }
  199. }
  200. }
  201. if ((lErr == ERROR_SUCCESS) &&
  202. (dwcbBuffer > 0) &&
  203. (dwType == REG_MULTI_SZ))
  204. {
  205. // parse each string
  206. TCHAR * lpszRegEntry = pszBuffer;
  207. while(*lpszRegEntry)
  208. {
  209. // caclulate length of entry
  210. int nLenEntry = _tcslen(lpszRegEntry);
  211. // ok its a valid endpoint so parse it
  212. TCHAR* pszProtseq = NULL;
  213. TCHAR* pszEndpointData = NULL;
  214. TCHAR* pszTmpDynamic = NULL;
  215. CEndpointData::EndpointFlags nDynamic;
  216. pszProtseq = _tcstok(lpszRegEntry, TEXT(", "));
  217. pszTmpDynamic = _tcstok(NULL, TEXT(", "));
  218. nDynamic = (CEndpointData::EndpointFlags) _ttoi(pszTmpDynamic);
  219. pszEndpointData = _tcstok(NULL, TEXT(", "));
  220. // at this point we should have the protseq, endpoint and flags
  221. // .. so add the entry
  222. // ignore result as we will continue even if one fails
  223. AddEndpoint(new CEndpointData(pszProtseq, nDynamic, pszEndpointData));
  224. lpszRegEntry += nLenEntry + 1;
  225. }
  226. }
  227. else if ((lErr != ERROR_SUCCESS) && (lErr != ERROR_FILE_NOT_FOUND))
  228. g_util.PostErrorMessage();
  229. delete pszBuffer;
  230. m_bChanged = FALSE;
  231. SetModified(FALSE);
  232. // select first item
  233. if (!m_colProtseqs.GetCount())
  234. // add default item
  235. m_colProtseqs.AddTail(m_epSysDefault);
  236. m_nSelected = 0;
  237. }
  238. //+-------------------------------------------------------------------------
  239. //
  240. // Member: CRpcOptionsPropertyPage::OnClearEndpoints
  241. //
  242. // Synopsis: Clears endpoint list and restores default settings
  243. //
  244. // Arguments: None
  245. //
  246. // Returns: Nothing
  247. //
  248. // Algorithm: N/A
  249. //
  250. // History: 02-Dec-96 Ronans Created
  251. //
  252. //--------------------------------------------------------------------------
  253. void CRpcOptionsPropertyPage::OnClearEndpoints()
  254. {
  255. // clear protocol list
  256. ClearProtocols();
  257. m_bChanged = TRUE;
  258. m_colProtseqs.AddTail(m_epSysDefault);
  259. m_nSelected = 0;
  260. RefreshEPList();
  261. SetModified(TRUE);
  262. SetFocus();
  263. }
  264. //+-------------------------------------------------------------------------
  265. //
  266. // Member: CRpcOptionsPropertyPage::OnRemoveEndpoint
  267. //
  268. // Synopsis: Updates display after removal of endpoint
  269. //
  270. // Arguments: None
  271. //
  272. // Returns: Nothing
  273. //
  274. // Algorithm: N/A
  275. //
  276. // History: 02-Dec-96 Ronans Created
  277. //
  278. //--------------------------------------------------------------------------
  279. void CRpcOptionsPropertyPage::OnRemoveEndpoint()
  280. {
  281. if (m_nSelected != (-1))
  282. {
  283. if (m_colProtseqs.GetCount() == 1)
  284. OnClearEndpoints();
  285. else
  286. {
  287. // get the corresponding endpoint data object
  288. CEndpointData * pData = (CEndpointData*) m_lstProtseqs.GetItemData(m_nSelected);
  289. POSITION pos = m_colProtseqs. Find(pData, NULL);
  290. if (pos)
  291. {
  292. // remove item
  293. m_colProtseqs.RemoveAt(pos);
  294. if (pData != m_epSysDefault)
  295. delete pData;
  296. // update item focus
  297. if (m_nSelected >= m_colProtseqs.GetCount())
  298. m_nSelected = -1;
  299. UpdateData(FALSE);
  300. m_bChanged = TRUE;
  301. SetModified(TRUE);
  302. RefreshEPList();
  303. SetFocus();
  304. }
  305. }
  306. }
  307. }
  308. //+-------------------------------------------------------------------------
  309. //
  310. // Member: CRpcOptionsPropertyPage::OnUpdateEndpoint
  311. //
  312. // Synopsis: Called to process update command btn on existing endpoint
  313. //
  314. // Arguments: None
  315. //
  316. // Returns: Nothing
  317. //
  318. // Algorithm: N/A
  319. //
  320. // History: 02-Dec-96 Ronans Created
  321. //
  322. //--------------------------------------------------------------------------
  323. void CRpcOptionsPropertyPage::OnUpdateEndpoint()
  324. {
  325. // if there's a current selection (should always be the case)
  326. if (m_nSelected != -1)
  327. {
  328. // get the corresponding endpoint data object
  329. CEndpointData * pData = (CEndpointData*) m_lstProtseqs.GetItemData(m_nSelected);
  330. if (pData != m_epSysDefault)
  331. {
  332. CEndpointDetails ced;
  333. ced.SetOperation( CEndpointDetails::opUpdateProtocol);
  334. ced.SetEndpointData(pData);
  335. if (ced.DoModal() == IDOK)
  336. {
  337. pData = ced.GetEndpointData(pData);
  338. m_bChanged = TRUE;
  339. SetModified(TRUE);
  340. RefreshEPList();
  341. }
  342. SetFocus();
  343. }
  344. }
  345. }
  346. //+-------------------------------------------------------------------------
  347. //
  348. // Member: CRpcOptionsPropertyPage::OnAddEndpoint
  349. //
  350. // Synopsis: Called to process add endpoint command button
  351. //
  352. // Arguments: None
  353. //
  354. // Returns: Nothing
  355. //
  356. // Algorithm: N/A
  357. //
  358. // History: 02-Dec-96 Ronans Created
  359. //
  360. //--------------------------------------------------------------------------
  361. void CRpcOptionsPropertyPage::OnAddEndpoint()
  362. {
  363. CEndpointDetails ced;
  364. ced.SetOperation( CEndpointDetails::opAddProtocol);
  365. if (ced.DoModal() == IDOK)
  366. {
  367. // create new endpoint
  368. CEndpointData *pNewEndpoint = new CEndpointData();
  369. ASSERT(pNewEndpoint);
  370. pNewEndpoint = ced.GetEndpointData(pNewEndpoint);
  371. ASSERT(pNewEndpoint);
  372. // check if protseq is already in collection
  373. POSITION pos = NULL;
  374. pos = m_colProtseqs.GetHeadPosition();
  375. while (pos != NULL)
  376. {
  377. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  378. if (pEPD -> m_pProtocol == pNewEndpoint -> m_pProtocol)
  379. {
  380. delete pNewEndpoint;
  381. pNewEndpoint = NULL;
  382. AfxMessageBox((UINT)IDS_DUPLICATE_PROTSEQ);
  383. break;
  384. }
  385. }
  386. // only add the endpoint if its not already in collection
  387. if (pNewEndpoint)
  388. {
  389. // reset old hilited item
  390. if (m_nSelected != -1)
  391. {
  392. m_lstProtseqs.SetItemState(m_nSelected, 0, LVIS_SELECTED | LVIS_FOCUSED);
  393. m_lstProtseqs.Update(m_nSelected);
  394. }
  395. // add new endpoint
  396. AddEndpoint(pNewEndpoint);
  397. // set new item in list
  398. CString sTmp;
  399. if (pNewEndpoint -> m_pProtocol)
  400. sTmp .LoadString(pNewEndpoint -> m_pProtocol -> nResidDesc);
  401. // insert item and store pointer to its associated CEndpointData
  402. int nImageNum = (pNewEndpoint -> m_nDynamicFlags != CEndpointData::edDisableEP) ? 0 : 1;
  403. m_nSelected = m_lstProtseqs.InsertItem(0, sTmp, nImageNum);
  404. if (m_nSelected != -1)
  405. {
  406. m_lstProtseqs.SetItemData(m_nSelected, (DWORD_PTR)pNewEndpoint);
  407. UpdateSelection();
  408. m_bChanged = TRUE;
  409. SetModified(TRUE);
  410. }
  411. }
  412. }
  413. SetFocus();
  414. }
  415. //+-------------------------------------------------------------------------
  416. //
  417. // Member: CRpcOptionsPropertyPage::ClearProtocols
  418. //
  419. // Synopsis: Clears protocol list
  420. //
  421. // Arguments: None
  422. //
  423. // Returns: Nothing
  424. //
  425. // Algorithm: N/A
  426. //
  427. // History: 02-Dec-96 Ronans Created
  428. //
  429. //--------------------------------------------------------------------------
  430. void CRpcOptionsPropertyPage::ClearProtocols()
  431. {
  432. // clean up endpoint data collection
  433. POSITION pos = NULL;
  434. pos = m_colProtseqs.GetHeadPosition();
  435. while (pos != NULL)
  436. {
  437. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  438. if (pEPD != m_epSysDefault)
  439. delete pEPD;
  440. }
  441. m_colProtseqs.RemoveAll();
  442. m_nSelected = -1;
  443. }
  444. //+-------------------------------------------------------------------------
  445. //
  446. // Member: CRpcOptionsPropertyPage::RefreshEPList
  447. //
  448. // Synopsis: Refreshes display from protocol list
  449. //
  450. // Arguments: None
  451. //
  452. // Returns: Nothing
  453. //
  454. // Algorithm: N/A
  455. //
  456. // History: 02-Dec-96 Ronans Created
  457. //
  458. //--------------------------------------------------------------------------
  459. void CRpcOptionsPropertyPage::RefreshEPList()
  460. {
  461. POSITION pos = m_colProtseqs.GetHeadPosition();
  462. // clear the list controls current contents
  463. m_lstProtseqs.DeleteAllItems();
  464. while (pos != NULL)
  465. {
  466. CString sTmp;
  467. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  468. if (pEPD -> m_pProtocol)
  469. sTmp .LoadString(pEPD -> m_pProtocol -> nResidDesc);
  470. // insert item and store pointer to its associated CEndpointData
  471. int nImageNum = (pEPD -> m_nDynamicFlags != CEndpointData::edDisableEP) ? 0 : 1;
  472. m_lstProtseqs.InsertItem(0, sTmp, nImageNum);
  473. m_lstProtseqs.SetItemData(0, (DWORD_PTR)pEPD);
  474. }
  475. UpdateSelection();
  476. }
  477. //+-------------------------------------------------------------------------
  478. //
  479. // Member: CRpcOptionsPropertyPage::AddEndpoint
  480. //
  481. // Synopsis: This method adds a new endpoint to the collection
  482. // of endpoints (m_colProtSeqs). If the collection justs consists of
  483. // the default endpoint, it removes it first.
  484. //
  485. // Arguments: pED - The new endpoint object to add
  486. //
  487. // Returns: Nothing
  488. //
  489. // Algorithm: N/A
  490. //
  491. // History: 02-Dec-96 Ronans Created
  492. //
  493. //--------------------------------------------------------------------------
  494. void CRpcOptionsPropertyPage::AddEndpoint(CEndpointData* pED)
  495. {
  496. // remove default item if present
  497. if ((m_colProtseqs.GetCount() == 1) &&
  498. (m_colProtseqs.GetHead() == m_epSysDefault))
  499. {
  500. m_colProtseqs.RemoveAll();
  501. if (m_lstProtseqs.GetItemCount())
  502. m_lstProtseqs.DeleteItem(0);
  503. }
  504. // add new item
  505. m_colProtseqs.AddTail(pED);
  506. m_bChanged = TRUE;
  507. }
  508. //+-------------------------------------------------------------------------
  509. //
  510. // Member: CRpcOptionsPropertyPage::OnSelectProtseq
  511. //
  512. // Synopsis: This method is called when an element is selected from the listview
  513. // containing the list of protocols and endpoints.
  514. // It updates the buttons and controls to reflect the current selection
  515. //
  516. // Arguments: Standard args for ListCtrl callbacks
  517. //
  518. // Returns: Nothing
  519. //
  520. // Algorithm: N/A
  521. //
  522. // History: 02-Dec-96 Ronans Created
  523. //
  524. //--------------------------------------------------------------------------
  525. void CRpcOptionsPropertyPage::OnSelectProtseq(NMHDR* pNMHDR, LRESULT* pResult)
  526. {
  527. m_nSelected = m_lstProtseqs.GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
  528. UpdateSelection();
  529. *pResult = 0;
  530. }
  531. //+-------------------------------------------------------------------------
  532. //
  533. // Member: CRpcOptionsPropertyPage::UpdateSelection
  534. //
  535. // Synopsis: Updates UI after protocol has been selected
  536. //
  537. // Arguments: None
  538. //
  539. // Returns: Nothing
  540. //
  541. // Algorithm: N/A
  542. //
  543. // History: 02-Dec-96 Ronans Created
  544. //
  545. //--------------------------------------------------------------------------
  546. void CRpcOptionsPropertyPage::UpdateSelection()
  547. {
  548. // check to see what buttons should be enabled
  549. if ((m_colProtseqs.GetCount() == 1) &&
  550. (m_colProtseqs.GetHead() == m_epSysDefault))
  551. {
  552. m_btnClear.EnableWindow(FALSE);
  553. m_btnRemove.EnableWindow(FALSE);
  554. m_btnUpdate.EnableWindow(FALSE);
  555. }
  556. else
  557. {
  558. m_btnClear.EnableWindow(TRUE);
  559. if (m_nSelected == -1)
  560. {
  561. m_btnRemove.EnableWindow(FALSE);
  562. m_btnUpdate.EnableWindow(FALSE);
  563. }
  564. else
  565. {
  566. // get the corresponding endpoint data object
  567. CEndpointData * pData = (CEndpointData*) m_lstProtseqs.GetItemData(m_nSelected);
  568. m_btnRemove.EnableWindow(TRUE);
  569. m_btnUpdate.EnableWindow(TRUE);
  570. }
  571. }
  572. // set up initial selection
  573. if (m_nSelected != (-1))
  574. {
  575. m_lstProtseqs.SetItemState(m_nSelected, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  576. m_lstProtseqs.Update(m_nSelected);
  577. }
  578. UpdateData(FALSE);
  579. }
  580. //+-------------------------------------------------------------------------
  581. //
  582. // Member: CRpcOptionsPropertyPage::OnSetActive
  583. //
  584. // Synopsis: Called when page is activated
  585. //
  586. // Arguments: None
  587. //
  588. // Returns: Nothing
  589. //
  590. // Algorithm: N/A
  591. //
  592. // History: 02-Dec-96 Ronans Created
  593. //
  594. //--------------------------------------------------------------------------
  595. BOOL CRpcOptionsPropertyPage::OnSetActive()
  596. {
  597. BOOL bRetval = CPropertyPage::OnSetActive();
  598. PostMessage(WM_SETFOCUS);
  599. return bRetval;
  600. }
  601. //+-------------------------------------------------------------------------
  602. //
  603. // Member: CRpcOptionsPropertyPage::OnSetFocus
  604. //
  605. // Synopsis: Called when page gets focus
  606. //
  607. // Arguments: None
  608. //
  609. // Returns: Nothing
  610. //
  611. // Algorithm: N/A
  612. //
  613. // History: 02-Dec-96 Ronans Created
  614. //
  615. //--------------------------------------------------------------------------
  616. void CRpcOptionsPropertyPage::OnSetFocus(CWnd* pOldWnd)
  617. {
  618. CPropertyPage::OnSetFocus(pOldWnd);
  619. m_lstProtseqs.SetFocus();
  620. if (m_nSelected != (-1))
  621. {
  622. m_lstProtseqs.SetItemState(m_nSelected, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  623. m_lstProtseqs.Update(m_nSelected);
  624. }
  625. else
  626. {
  627. TRACE(TEXT("Invalid state"));
  628. }
  629. }
  630. //+-------------------------------------------------------------------------
  631. //
  632. // Member: CRpcOptionsPropertyPage::OnKillFocus
  633. //
  634. // Synopsis: Called when page loses focus
  635. //
  636. // Arguments: None
  637. //
  638. // Returns: Nothing
  639. //
  640. // Algorithm: N/A
  641. //
  642. // History: 02-Dec-96 Ronans Created
  643. //
  644. //--------------------------------------------------------------------------
  645. void CRpcOptionsPropertyPage::OnKillFocus(CWnd* pNewWnd)
  646. {
  647. CPropertyPage::OnKillFocus(pNewWnd);
  648. }
  649. //+-------------------------------------------------------------------------
  650. //
  651. // Member: CRpcOptionsPropertyPage::OnKillActive
  652. //
  653. // Synopsis: Called when page is deactivated
  654. //
  655. // Arguments: None
  656. //
  657. // Returns: Nothing
  658. //
  659. // Algorithm: N/A
  660. //
  661. // History: 02-Dec-96 Ronans Created
  662. //
  663. //--------------------------------------------------------------------------
  664. BOOL CRpcOptionsPropertyPage::OnKillActive()
  665. {
  666. return CPropertyPage::OnKillActive();
  667. }
  668. //+-------------------------------------------------------------------------
  669. //
  670. // Member: CRpcOptionsPropertyPage::OnHelpInfo
  671. //
  672. // Synopsis: Called to display help info on items
  673. //
  674. // Arguments: None
  675. //
  676. // Returns: Nothing
  677. //
  678. // Algorithm: N/A
  679. //
  680. // History: 02-Dec-96 Ronans Created
  681. //
  682. //--------------------------------------------------------------------------
  683. BOOL CRpcOptionsPropertyPage::OnHelpInfo(HELPINFO* pHelpInfo)
  684. {
  685. if(-1 != pHelpInfo->iCtrlId)
  686. {
  687. WORD hiWord = 0x8000 | CRpcOptionsPropertyPage::IDD;
  688. WORD loWord = (WORD) pHelpInfo->iCtrlId;
  689. DWORD dwLong = MAKELONG(loWord,hiWord);
  690. WinHelp(dwLong, HELP_CONTEXTPOPUP);
  691. TRACE1("Help Id 0x%lx\n", dwLong);
  692. return TRUE;
  693. }
  694. else
  695. {
  696. return CPropertyPage::OnHelpInfo(pHelpInfo);
  697. }
  698. }
  699. void CRpcOptionsPropertyPage::OnPropertiesProtseq(NMHDR* pNMHDR, LRESULT* pResult)
  700. {
  701. m_nSelected = m_lstProtseqs.GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
  702. OnUpdateEndpoint();
  703. UpdateSelection();
  704. *pResult = 0;
  705. }
  706. //+-------------------------------------------------------------------------
  707. //
  708. // Member: CRpcOptionsPropertyPage::ValidateChanges
  709. //
  710. // Synopsis: To be called to validate the endpoint set before saving
  711. //
  712. // Arguments: None
  713. //
  714. // Returns: Nothing
  715. //
  716. // Algorithm: N/A
  717. //
  718. // History: 02-Dec-96 Ronans Created
  719. //
  720. //--------------------------------------------------------------------------
  721. BOOL CRpcOptionsPropertyPage::ValidateChanges()
  722. {
  723. UpdateData(TRUE);
  724. // only validate if data has changed
  725. if (m_bChanged)
  726. {
  727. // validate endpoint entries
  728. }
  729. return TRUE;
  730. }
  731. //+-------------------------------------------------------------------------
  732. //
  733. // Member: CRpcOptionsPropertyPage::UpdateChanges
  734. //
  735. // Synopsis: Called to update the changes to registry
  736. //
  737. // Arguments: None
  738. //
  739. // Returns: BOOL success flag
  740. //
  741. // Algorithm: N/A
  742. //
  743. // History: 27-Oct-97 Ronans Created
  744. //
  745. //--------------------------------------------------------------------------
  746. BOOL CRpcOptionsPropertyPage::UpdateChanges(HKEY hkAppID)
  747. {
  748. ASSERT(hkAppID != NULL);
  749. // only write the keys if there have been changes
  750. if (m_bChanged)
  751. {
  752. // write the DCOM endpoint data to the registry if necessary
  753. LONG lErr = ERROR_SUCCESS;
  754. // delete old key
  755. lErr = RegDeleteValue(hkAppID, TEXT("Endpoints"));
  756. // if we successfully deleted the old value (or
  757. // there was no old value) then write the new values
  758. if ((lErr == ERROR_SUCCESS) || (lErr == ERROR_FILE_NOT_FOUND))
  759. {
  760. POSITION pos = NULL;
  761. int inxEP = 0;
  762. int nLenRegString = 0;
  763. TCHAR * lpszBuffer , *lpszBuffer2;
  764. // calculate string length
  765. pos = m_colProtseqs.GetHeadPosition();
  766. while (pos != NULL)
  767. {
  768. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  769. ASSERT(pEPD != NULL);
  770. if (pEPD != m_epSysDefault)
  771. {
  772. // create string for saving
  773. CString sKeyValue;
  774. sKeyValue.Format(TEXT("%s,%d,%s"),
  775. (LPCTSTR)(pEPD -> m_szProtseq),
  776. pEPD -> m_nDynamicFlags,
  777. (LPCTSTR) pEPD -> m_szEndpoint);
  778. nLenRegString += sKeyValue.GetLength() + 1;
  779. }
  780. }
  781. // if the combined string length is zero, we don't need to write anything
  782. if (nLenRegString)
  783. {
  784. lpszBuffer2 = lpszBuffer = new TCHAR[nLenRegString+1];
  785. pos = m_colProtseqs.GetHeadPosition();
  786. while (pos != NULL)
  787. {
  788. CEndpointData *pEPD = (CEndpointData*)m_colProtseqs.GetNext(pos);
  789. if (pEPD != m_epSysDefault)
  790. {
  791. // create string for saving
  792. CString sKeyValue;
  793. sKeyValue.Format(TEXT("%s,%d,%s"),
  794. (LPCTSTR)(pEPD -> m_szProtseq),
  795. pEPD -> m_nDynamicFlags,
  796. (LPCTSTR) pEPD -> m_szEndpoint);
  797. lstrcpy(lpszBuffer2, sKeyValue);
  798. lpszBuffer2 += sKeyValue.GetLength() + 1; // skip over trailing null
  799. }
  800. }
  801. *lpszBuffer2 = 0;
  802. // write out the string
  803. lErr = RegSetValueEx(hkAppID,
  804. (LPCTSTR)TEXT("Endpoints"),
  805. NULL,
  806. REG_MULTI_SZ,
  807. (BYTE*)(LPCTSTR)lpszBuffer,
  808. (nLenRegString + 1) * sizeof(TCHAR));
  809. delete lpszBuffer;
  810. }
  811. }
  812. else
  813. g_util.PostErrorMessage();
  814. SetModified(FALSE);
  815. }
  816. return TRUE;
  817. }
  818. //+-------------------------------------------------------------------------
  819. //
  820. // Member: CRpcOptionsPropertyPage::CancelChanges
  821. //
  822. // Synopsis: Called to cancel the changes to registry
  823. //
  824. // Arguments: None
  825. //
  826. // Returns: BOOL success flag
  827. //
  828. // Algorithm: N/A
  829. //
  830. // History: 27-Oct-97 Ronans Created
  831. //
  832. //--------------------------------------------------------------------------
  833. BOOL CRpcOptionsPropertyPage::CancelChanges()
  834. {
  835. return TRUE;
  836. }