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.

152 lines
5.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C O N M A N 2 . C P P
  7. //
  8. // Contents: Connection manager 2.
  9. //
  10. // Notes:
  11. //
  12. // Author: ckotze 16 Mar 2001
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include <atlbase.h>
  18. #include "cobase.h"
  19. #include "conman.h"
  20. #include "conman2.h"
  21. #include "dialup.h"
  22. #include "ncnetcon.h"
  23. HRESULT CConnectionManager2::EnumConnectionProperties(OUT SAFEARRAY** ppsaConnectionProperties)
  24. {
  25. CComPtr<INetConnectionManager> pConMan;
  26. NETCON_PROPERTIES_EX* pPropsEx;
  27. HRESULT hr = S_OK;
  28. hr = CoCreateInstance(CLSID_ConnectionManager, NULL, CLSCTX_INPROC, IID_INetConnectionManager, reinterpret_cast<void**>(&pConMan));
  29. if (SUCCEEDED(hr))
  30. {
  31. CComPtr<IEnumNetConnection> pNetConnection;
  32. hr = pConMan->EnumConnections(NCME_DEFAULT, &pNetConnection);
  33. if (SUCCEEDED(hr))
  34. {
  35. INetConnection* pConn;
  36. ULONG ulFetched;
  37. LISTNETCONPROPEX listNCProperties;
  38. ITERNETCONPROPEX iterProps;
  39. HRESULT hrFetched = S_OK;
  40. do
  41. {
  42. hrFetched = pNetConnection->Next(1, &pConn, &ulFetched);
  43. if ( (S_OK == hr) && (ulFetched) )
  44. {
  45. CComPtr<INetConnection2> pConn2;
  46. hr = pConn->QueryInterface(IID_INetConnection2, reinterpret_cast<void**>(&pConn2));
  47. if (SUCCEEDED(hr))
  48. {
  49. hr = pConn2->GetPropertiesEx(&pPropsEx);
  50. }
  51. else
  52. {
  53. NETCON_PROPERTIES* pProps;
  54. hr = pConn->GetProperties(&pProps);
  55. if (SUCCEEDED(hr))
  56. {
  57. pPropsEx = reinterpret_cast<NETCON_PROPERTIES_EX*>(CoTaskMemAlloc(sizeof(NETCON_PROPERTIES_EX)));
  58. if (pPropsEx)
  59. {
  60. CComPtr<IPersistNetConnection> pPersistNetConnection;
  61. hr = pConn->QueryInterface(IID_IPersistNetConnection, reinterpret_cast<LPVOID *>(&pPersistNetConnection));
  62. if (SUCCEEDED(hr))
  63. {
  64. ZeroMemory(pPropsEx, sizeof(NETCON_PROPERTIES_EX));
  65. hr = HrBuildPropertiesExFromProperties(pProps, pPropsEx, pPersistNetConnection);
  66. }
  67. }
  68. else
  69. {
  70. hr = E_OUTOFMEMORY;
  71. }
  72. FreeNetconProperties(pProps);
  73. }
  74. }
  75. if (S_OK == hr)
  76. {
  77. listNCProperties.insert(listNCProperties.end(), pPropsEx);
  78. }
  79. else
  80. {
  81. TraceTag(ttidError, "Failed to retrieve connection information for connection. Connection will be ommitted from Connections Folder.");
  82. }
  83. ReleaseObj(pConn);
  84. }
  85. } while ( (S_OK == hrFetched) && (ulFetched) );
  86. if (listNCProperties.size())
  87. {
  88. hr = S_OK;
  89. if (listNCProperties.size() != 0)
  90. {
  91. SAFEARRAYBOUND rgsaBound[1];
  92. LONG lIndex;
  93. rgsaBound[0].cElements = listNCProperties.size();
  94. rgsaBound[0].lLbound = 0;
  95. lIndex = rgsaBound[0].lLbound;
  96. *ppsaConnectionProperties = SafeArrayCreate(VT_VARIANT, 1, rgsaBound);
  97. for (ITERNETCONPROPEX iter = listNCProperties.begin(); iter != listNCProperties.end(); iter++)
  98. {
  99. HRESULT hrT = S_OK;
  100. VARIANT varElement;
  101. SAFEARRAY* psaPropertiesEx = NULL;
  102. pPropsEx = *iter;
  103. hrT = HrSafeArrayFromNetConPropertiesEx(pPropsEx, &psaPropertiesEx);
  104. if (SUCCEEDED(hrT))
  105. {
  106. VariantInit(&varElement);
  107. varElement.vt = VT_VARIANT | VT_ARRAY;
  108. varElement.parray = psaPropertiesEx;
  109. hrT = SafeArrayPutElement(*ppsaConnectionProperties, &lIndex, &varElement);
  110. VariantClear(&varElement);
  111. }
  112. if (FAILED(hrT))
  113. {
  114. hr = hrT;
  115. break;
  116. }
  117. lIndex++;
  118. }
  119. }
  120. }
  121. for (ITERNETCONPROPEX iter = listNCProperties.begin(); iter != listNCProperties.end(); iter++)
  122. {
  123. HrFreeNetConProperties2(*iter);
  124. }
  125. }
  126. }
  127. if (SUCCEEDED(hr) && !(*ppsaConnectionProperties) )
  128. {
  129. hr = S_FALSE;
  130. }
  131. TraceHr (ttidError, FAL, hr, FALSE, "CConnectionManager2::EnumConnectionProperties");
  132. return hr;
  133. }