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.

169 lines
4.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File:
  7. //
  8. // Contents: A C S H E E T . C P P
  9. //
  10. // Notes: Advanced Configuration property sheet code
  11. //
  12. // Author: danielwe 14 Jul 1998
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "acsheet.h"
  18. #include "acbind.h"
  19. #include "netcfgx.h"
  20. #include "order.h"
  21. const INT c_cmaxPages = 3;
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Member: HrGetINetCfg
  25. //
  26. // Purpose: Obtains the INetCfg with lock
  27. //
  28. // Arguments:
  29. // (none)
  30. //
  31. // Returns: S_OK if success, OLE or Win32 error otherwise
  32. //
  33. // Author: danielwe 3 Dec 1997
  34. //
  35. // Notes:
  36. //
  37. HRESULT HrGetINetCfg(HWND hwndParent, INetCfg **ppnc, INetCfgLock **ppnclock)
  38. {
  39. HRESULT hr = S_OK;
  40. INetCfg * pnc = NULL;
  41. INetCfgLock * pnclock = NULL;
  42. Assert(ppnc);
  43. Assert(ppnclock);
  44. *ppnc = NULL;
  45. *ppnclock = NULL;
  46. hr = CoCreateInstance(CLSID_CNetCfg, NULL,
  47. CLSCTX_INPROC_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  48. IID_INetCfg, reinterpret_cast<void**>(&pnc));
  49. if (SUCCEEDED(hr))
  50. {
  51. hr = pnc->QueryInterface(IID_INetCfgLock,
  52. reinterpret_cast<LPVOID *>(&pnclock));
  53. if (SUCCEEDED(hr))
  54. {
  55. PWSTR pszwLockHolder;
  56. hr = pnclock->AcquireWriteLock(0,
  57. SzLoadIds(IDS_ADVCFG_LOCK_DESC), &pszwLockHolder);
  58. if (S_OK == hr)
  59. {
  60. Assert(!pszwLockHolder);
  61. hr = pnc->Initialize(NULL);
  62. }
  63. else if (S_FALSE == hr)
  64. {
  65. // Couldn't lock INetCfg
  66. NcMsgBox(hwndParent,
  67. IDS_ADVCFG_CAPTION, IDS_ADVCFG_CANT_LOCK,
  68. MB_ICONSTOP | MB_OK,
  69. (pszwLockHolder)
  70. ? pszwLockHolder
  71. : SzLoadIds(IDS_ADVCFG_GENERIC_COMP));
  72. CoTaskMemFree(pszwLockHolder);
  73. // Don't need this anymore
  74. ReleaseObj(pnclock);
  75. pnclock = NULL;
  76. hr = E_FAIL;
  77. }
  78. else if (NETCFG_E_NEED_REBOOT == hr)
  79. {
  80. // Can't make any changes because we are pending a reboot.
  81. NcMsgBox(hwndParent,
  82. IDS_ADVCFG_CAPTION, IDS_ADVCFG_NEED_REBOOT,
  83. MB_ICONSTOP | MB_OK);
  84. // Don't need this anymore
  85. ReleaseObj(pnclock);
  86. pnclock = NULL;
  87. }
  88. }
  89. }
  90. if (SUCCEEDED(hr))
  91. {
  92. *ppnc = pnc;
  93. *ppnclock = pnclock;
  94. }
  95. TraceError("HrGetINetCfg", hr);
  96. return hr;
  97. }
  98. HRESULT HrDoAdvCfgDlg(HWND hwndParent)
  99. {
  100. PROPSHEETHEADER psh = {0};
  101. HPROPSHEETPAGE ahpsp[c_cmaxPages];
  102. INetCfg * pnc = NULL;
  103. INetCfgLock * pnclock = NULL;
  104. HRESULT hr;
  105. hr = HrGetINetCfg(hwndParent, &pnc, &pnclock);
  106. if (SUCCEEDED(hr))
  107. {
  108. CBindingsDlg dlgBindings(pnc);
  109. CProviderOrderDlg dlgProviderOrder;
  110. DWORD cPages = 0;
  111. if (dlgBindings.FShowPage())
  112. {
  113. ahpsp[cPages++] = dlgBindings.CreatePage(IDD_ADVCFG_Bindings, 0);
  114. }
  115. if (dlgProviderOrder.FShowPage())
  116. {
  117. ahpsp[cPages++] = dlgProviderOrder.CreatePage(IDD_ADVCFG_Provider, 0);
  118. }
  119. psh.dwSize = sizeof(PROPSHEETHEADER);
  120. psh.dwFlags = PSH_NOAPPLYNOW;
  121. psh.hwndParent = hwndParent;
  122. psh.hInstance = _Module.GetResourceInstance();
  123. psh.pszCaption = SzLoadIds(IDS_ADVCFG_PROPSHEET_TITLE);
  124. psh.nPages = cPages;
  125. psh.phpage = ahpsp;
  126. int nRet = (int)PropertySheet(&psh);
  127. hr = pnc->Uninitialize();
  128. if (SUCCEEDED(hr))
  129. {
  130. if (pnclock)
  131. {
  132. // Don't unlock unless we previously successfully acquired the
  133. // write lock
  134. hr = pnclock->ReleaseWriteLock();
  135. ReleaseObj(pnclock);
  136. }
  137. }
  138. if (SUCCEEDED(hr))
  139. {
  140. ReleaseObj(pnc);
  141. }
  142. }
  143. TraceError("HrDoAdvCfgDlg", hr);
  144. return hr;
  145. }