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.

184 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module ConnDlg.cpp | Implementation of the main dialog
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 07/22/1999
  9. Revision History:
  10. Name Date Comments
  11. aoltean 07/22/1999 Created
  12. aoltean 08/05/1999 Splitting wizard functionality in a base class
  13. aoltean 09/26/1999 Better interface pointers management with ATL smart pointers
  14. --*/
  15. /////////////////////////////////////////////////////////////////////////////
  16. // Includes
  17. #include "stdafx.hxx"
  18. #include "resource.h"
  19. #include "GenDlg.h"
  20. #include "VssTest.h"
  21. #include "CoordDlg.h"
  22. #include "ConnDlg.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // Utility defines
  30. #define STR2W(str) ((LPTSTR)((LPCTSTR)(str)))
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CConnectDlg dialog
  33. CConnectDlg::CConnectDlg(CWnd* pParent /*=NULL*/)
  34. : CVssTestGenericDlg(CConnectDlg::IDD, pParent)
  35. {
  36. //{{AFX_DATA_INIT(CConnectDlg)
  37. m_strMachineName = _T("");
  38. //}}AFX_DATA_INIT
  39. m_bRemote = FALSE;
  40. }
  41. CConnectDlg::~CConnectDlg()
  42. {
  43. }
  44. void CConnectDlg::DoDataExchange(CDataExchange* pDX)
  45. {
  46. CVssTestGenericDlg::DoDataExchange(pDX);
  47. //{{AFX_DATA_MAP(CConnectDlg)
  48. DDX_Text(pDX, IDC_CONN_MACHINE_NAME, m_strMachineName);
  49. //}}AFX_DATA_MAP
  50. }
  51. BEGIN_MESSAGE_MAP(CConnectDlg, CVssTestGenericDlg)
  52. //{{AFX_MSG_MAP(CConnectDlg)
  53. ON_BN_CLICKED(IDC_NEXT, OnNext)
  54. ON_BN_CLICKED(IDC_CONN_LOCAL, OnLocal)
  55. ON_BN_CLICKED(IDC_CONN_REMOTE, OnRemote)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CConnectDlg message handlers
  60. BOOL CConnectDlg::OnInitDialog()
  61. {
  62. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CConnectDlg::OnInitDialog" );
  63. USES_CONVERSION;
  64. try
  65. {
  66. CVssTestGenericDlg::OnInitDialog();
  67. UpdateData( FALSE );
  68. BOOL bRes = ::CheckRadioButton( m_hWnd, IDC_CONN_LOCAL, IDC_CONN_REMOTE, IDC_CONN_LOCAL );
  69. _ASSERTE( bRes );
  70. }
  71. VSS_STANDARD_CATCH(ft)
  72. return TRUE; // return TRUE unless you set the focus to a control
  73. }
  74. void CConnectDlg::OnNext()
  75. {
  76. CVssFunctionTracer ft( VSSDBG_VSSTEST, L"CConnectDlg::OnNext" );
  77. USES_CONVERSION;
  78. CComPtr<IVssCoordinator> pICoord;
  79. try
  80. {
  81. UpdateData();
  82. if (m_bRemote)
  83. {
  84. COSERVERINFO serverInfo;
  85. MULTI_QI sMultiQI;
  86. IID iid = IID_IVssCoordinator;
  87. // Zero out these structures
  88. VssZeroOut(&serverInfo);
  89. VssZeroOut(&sMultiQI);
  90. serverInfo.pwszName = STR2W(m_strMachineName);
  91. sMultiQI.pIID = &iid;
  92. ft.hr = ::CoCreateInstanceEx( CLSID_VSSCoordinator,
  93. NULL, CLSCTX_REMOTE_SERVER, &serverInfo, 1, &sMultiQI);
  94. if ( ft.HrFailed() )
  95. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Connection failed.\n hr = 0x%08lx", ft.hr);
  96. BS_ASSERT(sMultiQI.pItf != NULL);
  97. BS_ASSERT(sMultiQI.hr == S_OK);
  98. pICoord.Attach(reinterpret_cast<IVssCoordinator*>(sMultiQI.pItf));
  99. }
  100. else
  101. {
  102. ft.hr = pICoord.CoCreateInstance( CLSID_VSSCoordinator );
  103. if ( ft.HrFailed() )
  104. ft.ErrBox( VSSDBG_VSSTEST, E_UNEXPECTED, L"Connection failed with hr = 0x%08lx", ft.hr);
  105. }
  106. BS_ASSERT( pICoord != NULL );
  107. ShowWindow(SW_HIDE);
  108. CCoordDlg dlg(pICoord);
  109. if (dlg.DoModal() == IDCANCEL)
  110. EndDialog(IDCANCEL);
  111. else
  112. ShowWindow(SW_SHOW);
  113. }
  114. VSS_STANDARD_CATCH(ft)
  115. }
  116. void CConnectDlg::OnLocal()
  117. {
  118. CWnd *pWnd;
  119. pWnd = GetDlgItem(IDC_CONN_STATIC_MACHINE_NAME);
  120. if (pWnd)
  121. pWnd->EnableWindow(FALSE);
  122. pWnd = GetDlgItem(IDC_CONN_MACHINE_NAME);
  123. if (pWnd)
  124. pWnd->EnableWindow(FALSE);
  125. m_bRemote = FALSE;
  126. }
  127. void CConnectDlg::OnRemote()
  128. {
  129. CWnd *pWnd;
  130. pWnd = GetDlgItem(IDC_CONN_STATIC_MACHINE_NAME);
  131. if (pWnd)
  132. pWnd->EnableWindow(TRUE);
  133. pWnd = GetDlgItem(IDC_CONN_MACHINE_NAME);
  134. if (pWnd)
  135. pWnd->EnableWindow(TRUE);
  136. m_bRemote = TRUE;
  137. }