Source code of Windows XP (NT5)
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.

158 lines
3.9 KiB

  1. #include "pch.h"
  2. #include <snapbase.h>
  3. #include "editimpl.h"
  4. HRESULT CAttributeEditor::Initialize(
  5. IADs* pADsObj,
  6. LPDS_ATTREDITOR_BINDINGINFO pBindingInfo,
  7. CADSIEditPropertyPageHolder* pHolder)
  8. {
  9. TRACE(_T("CAttributeEditor::Initialize()\n"));
  10. m_spIADs = pADsObj;
  11. ASSERT(pBindingInfo != NULL);
  12. ASSERT(pBindingInfo->lpfnBind != NULL);
  13. ASSERT(pBindingInfo->lpszProviderServer != NULL);
  14. m_BindingInfo.lParam = pBindingInfo->lParam;
  15. m_BindingInfo.lpfnBind = pBindingInfo->lpfnBind;
  16. m_BindingInfo.dwFlags = pBindingInfo->dwFlags;
  17. int nCount = wcslen(pBindingInfo->lpszProviderServer);
  18. m_BindingInfo.lpszProviderServer = new WCHAR[nCount + 1];
  19. wcscpy(m_BindingInfo.lpszProviderServer, pBindingInfo->lpszProviderServer);
  20. m_BindingInfo.dwSize = sizeof(DS_ATTREDITOR_BINDINGINFO);
  21. m_pHolder = pHolder;
  22. ASSERT(m_pHolder);
  23. //
  24. // Retrieve the class name
  25. //
  26. CComBSTR bstrClass;
  27. HRESULT hr = S_OK;
  28. hr = m_spIADs->get_Class(&bstrClass);
  29. if (SUCCEEDED(hr))
  30. {
  31. m_szClass = bstrClass;
  32. }
  33. return hr;
  34. }
  35. HRESULT CAttributeEditor::CreateModal()
  36. {
  37. TRACE(_T("CAttributeEditor::CreateModal()\n"));
  38. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  39. //
  40. // Build the abstract schema path
  41. //
  42. CString szSchemaClass(m_BindingInfo.lpszProviderServer);
  43. szSchemaClass = szSchemaClass + _T("schema/") + m_szClass;
  44. //
  45. // Bind to the class object in the abstract schema
  46. //
  47. HRESULT hr = S_OK;
  48. CComPtr<IADsClass> spIADsClass;
  49. if (m_BindingInfo.dwFlags & DSATTR_EDITOR_ROOTDSE)
  50. {
  51. //
  52. // Trying to bind to the schema class of the RootDSE will fail.
  53. // Just pass NULL instead
  54. //
  55. spIADsClass = NULL;
  56. }
  57. else
  58. {
  59. hr = m_BindingInfo.lpfnBind((LPWSTR)(LPCWSTR)szSchemaClass,
  60. ADS_SECURE_AUTHENTICATION,
  61. IID_IADsClass,
  62. (PVOID*)&spIADsClass,
  63. m_BindingInfo.lParam);
  64. }
  65. if (SUCCEEDED(hr))
  66. {
  67. //
  68. // Invoke the editor
  69. //
  70. m_pEditor = new CAttributeEditorPropertyPage(m_spIADs, spIADsClass, &m_BindingInfo, m_pHolder);
  71. if (m_pEditor)
  72. {
  73. CPropertySheet* m_pDummySheet = new CPropertySheet();
  74. if (m_pDummySheet)
  75. {
  76. m_pDummySheet->m_psh.dwFlags |= PSH_NOAPPLYNOW;
  77. CString szCaption;
  78. VERIFY(szCaption.LoadString(IDS_ATTREDITOR_CAPTION));
  79. m_pDummySheet->m_psh.pszCaption = szCaption;
  80. m_pDummySheet->AddPage(m_pEditor);
  81. hr = (m_pDummySheet->DoModal() == IDOK) ? S_OK : S_FALSE;
  82. }
  83. delete m_pEditor;
  84. m_pEditor = NULL;
  85. }
  86. }
  87. return hr;
  88. }
  89. HRESULT CAttributeEditor::GetPage(HPROPSHEETPAGE* phPropSheetPage)
  90. {
  91. TRACE(_T("CAttributeEditor::GetPage()\n"));
  92. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  93. //
  94. // Build the abstract schema path
  95. //
  96. CString szSchemaClass(m_BindingInfo.lpszProviderServer);
  97. szSchemaClass = szSchemaClass + _T("schema/") + m_szClass;
  98. //
  99. // Bind to the class object in the abstract schema
  100. //
  101. HRESULT hr = S_OK;
  102. CComPtr<IADsClass> spIADsClass;
  103. if (m_BindingInfo.dwFlags & DSATTR_EDITOR_ROOTDSE)
  104. {
  105. //
  106. // Trying to bind to the schema class of the RootDSE will fail.
  107. // Just pass NULL instead
  108. //
  109. spIADsClass = NULL;
  110. }
  111. else
  112. {
  113. hr = m_BindingInfo.lpfnBind((LPWSTR)(LPCWSTR)szSchemaClass,
  114. ADS_SECURE_AUTHENTICATION,
  115. IID_IADsClass,
  116. (PVOID*)&spIADsClass,
  117. m_BindingInfo.lParam);
  118. }
  119. if (SUCCEEDED(hr))
  120. {
  121. //
  122. // Invoke the editor
  123. //
  124. m_pEditor = new CAttributeEditorPropertyPage(m_spIADs, spIADsClass, &m_BindingInfo, m_pHolder);
  125. *phPropSheetPage = CreatePropertySheetPage((PROPSHEETPAGE*)(&m_pEditor->m_psp));
  126. if (*phPropSheetPage == NULL)
  127. {
  128. hr = E_FAIL;
  129. }
  130. }
  131. else
  132. {
  133. ADSIEditErrorMessage(hr);
  134. }
  135. return hr;
  136. }