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.

226 lines
5.6 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "commconn.h" // Standard shell\commconn includes
  4. #include "commconp.h" // Private shell\commconn includes
  5. #include "conprops.h"
  6. #include "nceh.h"
  7. #include "resource.h"
  8. #include "wizentry.h"
  9. CConnectionCommonUi::CConnectionCommonUi() :
  10. m_pconMan(NULL),
  11. m_hIL(NULL)
  12. {
  13. }
  14. CConnectionCommonUi::~CConnectionCommonUi()
  15. {
  16. ReleaseObj(m_pconMan);
  17. if (NULL != m_hIL)
  18. ImageList_Destroy(m_hIL);
  19. }
  20. HRESULT CConnectionCommonUi::HrInitialize()
  21. {
  22. HRESULT hr = NOERROR;
  23. // Get the connection manager if we haven't already
  24. if (NULL == m_pconMan)
  25. {
  26. INITCOMMONCONTROLSEX iccex = {0};
  27. iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  28. iccex.dwICC = ICC_USEREX_CLASSES;
  29. hr = HrCreateInstance(
  30. CLSID_ConnectionManager,
  31. CLSCTX_LOCAL_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  32. &m_pconMan);
  33. TraceHr(ttidError, FAL, hr, FALSE, "HrCreateInstance");
  34. if (FAILED(hr))
  35. goto Error;
  36. // Init the new common controls
  37. if (FALSE == InitCommonControlsEx(&iccex))
  38. {
  39. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  40. goto Error;
  41. }
  42. hr = CChooseConnectionDlg::HrLoadImageList(&m_hIL);
  43. }
  44. Error:
  45. TraceError("CConnectionCommonUi::HrInitialize",hr);
  46. return hr;
  47. }
  48. HRESULT CConnectionCommonUi::ChooseConnection(
  49. NETCON_CHOOSECONN * pChooseConn,
  50. INetConnection** ppConn)
  51. {
  52. HRESULT hr = E_POINTER;
  53. COM_PROTECT_TRY
  54. {
  55. INT_PTR nRet;
  56. CChooseConnectionDlg * pdlg = NULL;
  57. // Parameter Validation
  58. if ((NULL == pChooseConn) ||
  59. IsBadReadPtr(pChooseConn, sizeof(NETCON_CHOOSECONN)) ||
  60. ((NULL != ppConn) && IsBadWritePtr(ppConn, sizeof(INetConnection*))))
  61. {
  62. goto Error;
  63. }
  64. if ((sizeof(NETCON_CHOOSECONN) != pChooseConn->lStructSize) ||
  65. ((~NCCHT_ALL) & pChooseConn->dwTypeMask) ||
  66. ((NULL != pChooseConn->hwndParent) && !IsWindow(pChooseConn->hwndParent)) ||
  67. (~(NCCHF_CONNECT | NCCHF_CAPTION | NCCHF_AUTOSELECT |
  68. NCCHF_OKBTTNTEXT | NCCHF_DISABLENEW) & pChooseConn->dwFlags))
  69. {
  70. hr = E_INVALIDARG;
  71. goto Error;
  72. }
  73. if ((pChooseConn->dwFlags & NCCHF_CAPTION) &&
  74. ((NULL == pChooseConn->lpstrCaption) ||
  75. IsBadStringPtr(pChooseConn->lpstrCaption, 1024)))
  76. {
  77. goto Error;
  78. }
  79. if ((pChooseConn->dwFlags & NCCHF_OKBTTNTEXT) &&
  80. ((NULL == pChooseConn->lpstrOkBttnText) ||
  81. IsBadStringPtr(pChooseConn->lpstrOkBttnText, 1024)))
  82. {
  83. goto Error;
  84. }
  85. // Initialize
  86. hr = HrInitialize();
  87. if (FAILED(hr))
  88. {
  89. goto Error;
  90. }
  91. // Render the dialog
  92. Assert(PConMan());
  93. pdlg = new CChooseConnectionDlg(pChooseConn, this, ppConn);
  94. if (NULL == pdlg)
  95. {
  96. hr = E_OUTOFMEMORY;
  97. goto Error;
  98. }
  99. hr = S_OK;
  100. nRet = DialogBoxParam(_Module.GetResourceInstance(),
  101. MAKEINTRESOURCE(IDD_ConnChooser),
  102. pChooseConn->hwndParent,
  103. CChooseConnectionDlg::dlgprocConnChooser,
  104. (LPARAM)pdlg);
  105. if (IDOK != nRet)
  106. {
  107. hr = S_FALSE;
  108. }
  109. delete pdlg;
  110. Error:
  111. ;
  112. }
  113. COM_PROTECT_CATCH
  114. TraceErrorOptional("CConnectionCommonUi::ChooseConnection", hr, (S_FALSE==hr));
  115. return hr;
  116. }
  117. HRESULT CConnectionCommonUi::ShowConnectionProperties (
  118. HWND hwndParent,
  119. INetConnection* pCon)
  120. {
  121. HRESULT hr = E_INVALIDARG;
  122. INetConnection * pConnTmp = NULL;
  123. COM_PROTECT_TRY
  124. {
  125. // Parameter Validation
  126. if (((NULL != hwndParent) && !IsWindow(hwndParent)))
  127. {
  128. goto Error;
  129. }
  130. if ((NULL == pCon) || IsBadReadPtr(pCon, sizeof(INetConnection*)))
  131. {
  132. hr = E_POINTER;
  133. goto Error;
  134. }
  135. if (FAILED(HrQIAndSetProxyBlanket(pCon, &pConnTmp)))
  136. {
  137. hr = E_NOINTERFACE;
  138. goto Error;
  139. }
  140. Assert(NULL != pConnTmp);
  141. pConnTmp->Release();
  142. // Initialize
  143. hr = HrInitialize();
  144. if (FAILED(hr))
  145. {
  146. goto Error;
  147. }
  148. hr = HrRaiseConnectionProperties(hwndParent, pCon);
  149. Error:
  150. ;
  151. }
  152. COM_PROTECT_CATCH
  153. TraceErrorOptional("CConnectionCommonUi::ShowConnectionProperties", hr, (S_FALSE==hr));
  154. return hr;
  155. }
  156. HRESULT CConnectionCommonUi::StartNewConnectionWizard (
  157. HWND hwndParent,
  158. INetConnection** ppCon)
  159. {
  160. HRESULT hr = E_INVALIDARG;
  161. COM_PROTECT_TRY
  162. {
  163. // Parameter Validation
  164. if ((NULL != hwndParent) && !IsWindow(hwndParent))
  165. {
  166. goto Error;
  167. }
  168. if ((NULL == ppCon) || IsBadWritePtr(ppCon, sizeof(INetConnection*)))
  169. {
  170. hr = E_POINTER;
  171. goto Error;
  172. }
  173. // Initialize
  174. hr = HrInitialize();
  175. if (FAILED(hr))
  176. {
  177. goto Error;
  178. }
  179. *ppCon = NULL;
  180. hr = NetSetupAddRasConnection(hwndParent, ppCon);
  181. Error:
  182. ;
  183. }
  184. COM_PROTECT_CATCH
  185. TraceErrorOptional("CConnectionCommonUi::StartNewConnectionWizard", hr, (S_FALSE==hr));
  186. return hr;
  187. }