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.

194 lines
3.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: rasprof.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "rasdial.h"
  12. #include "rasprof.h"
  13. #include "profsht.h"
  14. #include "pgiasadv.h"
  15. //========================================
  16. //
  17. // Open profile UI API -- expose advanced page
  18. //
  19. // critical section protected pointer map
  20. class CAdvPagePointerMap
  21. {
  22. public:
  23. ~CAdvPagePointerMap()
  24. {
  25. HPROPSHEETPAGE hPage = NULL;
  26. CPgIASAdv* pPage = NULL;
  27. m_cs.Lock();
  28. POSITION pos = m_mPointers.GetStartPosition();
  29. while(pos)
  30. {
  31. m_mPointers.GetNextAssoc(pos, hPage, pPage);
  32. if(pPage)
  33. delete pPage;
  34. }
  35. m_mPointers.RemoveAll();
  36. m_cs.Unlock();
  37. };
  38. BOOL AddItem(HPROPSHEETPAGE hPage, CPgIASAdv* pPage)
  39. {
  40. BOOL bRet = TRUE;
  41. if(!pPage || !hPage)
  42. return FALSE;
  43. m_cs.Lock();
  44. try{
  45. m_mPointers.SetAt(hPage, pPage);
  46. }catch(...)
  47. {
  48. bRet = FALSE;
  49. }
  50. m_cs.Unlock();
  51. return bRet;
  52. };
  53. CPgIASAdv* FindAndRemoveItem(HPROPSHEETPAGE hPage)
  54. {
  55. CPgIASAdv* pPage = NULL;
  56. if (!hPage)
  57. return NULL;
  58. m_cs.Lock();
  59. m_mPointers.Lookup(hPage, pPage);
  60. m_mPointers.RemoveKey(hPage);
  61. m_cs.Unlock();
  62. return pPage;
  63. };
  64. protected:
  65. CMap<HPROPSHEETPAGE, HPROPSHEETPAGE, CPgIASAdv*, CPgIASAdv*> m_mPointers;
  66. CCriticalSection m_cs;
  67. } AdvancedPagePointerMap;
  68. //========================================
  69. //
  70. // Open profile UI API -- expose advanced page
  71. //
  72. // create a profile advanced page
  73. DllExport HPROPSHEETPAGE
  74. WINAPI
  75. IASCreateProfileAdvancedPage(
  76. ISdo* pProfile,
  77. ISdoDictionaryOld* pDictionary,
  78. LONG lFilter, // Mask used to test which attributes will be included.
  79. void* pvData // Contains std::vector< CComPtr< IIASAttributeInfo > > *
  80. )
  81. {
  82. HPROPSHEETPAGE hPage = NULL;
  83. CPgIASAdv* pPage = NULL;
  84. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  85. try{
  86. pPage = new CPgIASAdv(pProfile, pDictionary);
  87. if(pPage)
  88. {
  89. pPage->SetData(lFilter, pvData);
  90. hPage = ::CreatePropertySheetPage(&pPage->m_psp);
  91. if (!hPage)
  92. delete pPage;
  93. else
  94. AdvancedPagePointerMap.AddItem(hPage, pPage);
  95. }
  96. }
  97. catch (...)
  98. {
  99. SetLastError(ERROR_OUTOFMEMORY);
  100. if(pPage)
  101. {
  102. delete pPage;
  103. pPage = NULL;
  104. hPage = NULL;
  105. }
  106. }
  107. return hPage;
  108. }
  109. //========================================
  110. //
  111. // Open profile UI API -- expose advanced page
  112. //
  113. // clean up the resources used by C++ object
  114. DllExport BOOL
  115. WINAPI
  116. IASDeleteProfileAdvancedPage(
  117. HPROPSHEETPAGE hPage
  118. )
  119. {
  120. CPgIASAdv* pPage = AdvancedPagePointerMap.FindAndRemoveItem(hPage);
  121. if (!pPage) return FALSE;
  122. delete pPage;
  123. return TRUE;
  124. }
  125. //========================================
  126. //
  127. // Open profile UI API
  128. //
  129. DllExport HRESULT OpenRAS_IASProfileDlg(
  130. LPCWSTR pMachineName,
  131. ISdo* pProfile, // profile SDO pointer
  132. ISdoDictionaryOld * pDictionary, // dictionary SDO pointer
  133. BOOL bReadOnly, // if the dlg is for readonly
  134. DWORD dwTabFlags, // what to show
  135. void *pvData // additional data
  136. )
  137. {
  138. HRESULT hr = S_OK;
  139. if(!pProfile || !pDictionary)
  140. return E_INVALIDARG;
  141. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  142. CRASProfileMerge profile(pProfile, pDictionary);
  143. profile.SetMachineName(pMachineName);
  144. hr = profile.Load();
  145. if(!FAILED(hr))
  146. {
  147. CProfileSheetMerge sh(profile, true, IDS_EDITDIALINPROFILE);
  148. sh.SetReadOnly(bReadOnly);
  149. sh.PreparePages(dwTabFlags, pvData);
  150. if(IDOK == sh.DoModal())
  151. {
  152. if(sh.GetLastError() != S_OK)
  153. hr = sh.GetLastError();
  154. else if(!sh.IsApplied())
  155. hr = S_FALSE;
  156. }
  157. else
  158. hr = S_FALSE;
  159. }
  160. return hr;
  161. }