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.

133 lines
3.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: loadconnfolder.cpp
  4. //
  5. // Module: CMSTP.EXE
  6. //
  7. // Synopsis: This source file contains the code that implements the
  8. // CLoadConnFolder Class.
  9. //
  10. // Copyright (c) 1997-1999 Microsoft Corporation
  11. //
  12. // Author: quintinb Created 07/14/98
  13. //
  14. //+----------------------------------------------------------------------------
  15. #include "cmmaster.h"
  16. CLoadConnFolder::CLoadConnFolder()
  17. {
  18. ULONG ulCount;
  19. // "CLSID_MyComputer\CLSID_ControlPanel\CLSID_ConnectionsFolder"
  20. // Note -- ParseDisplayName() is miss declared, it should take a const ptr
  21. //
  22. #define NETCON_FOLDER_PATH L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\" \
  23. L"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\" \
  24. L"::{7007acc7-3202-11d1-aad2-00805fc1270e}";
  25. WCHAR c_szMyFolderName[] = NETCON_FOLDER_PATH;
  26. //
  27. // Set initial states of class vars
  28. //
  29. m_pConnectionsFolder = NULL;
  30. m_ConnFolderpidl = NULL;
  31. m_pDesktopFolder = NULL;
  32. m_HrClassState = E_UNEXPECTED;
  33. //
  34. // Start retrieving the conn folder
  35. //
  36. m_HrClassState = CoInitialize(NULL);
  37. //
  38. // Save whether CoInit succeeded or not
  39. //
  40. m_CoInit = SUCCEEDED(m_HrClassState);
  41. if (SUCCEEDED(m_HrClassState))
  42. {
  43. //
  44. // Get the desktop folder, so we can parse the display name and get
  45. // the UI object of the connections folder
  46. //
  47. m_HrClassState = SHGetDesktopFolder(&m_pDesktopFolder);
  48. if (SUCCEEDED(m_HrClassState))
  49. {
  50. m_HrClassState = m_pDesktopFolder->ParseDisplayName(NULL, 0, (WCHAR *) c_szMyFolderName,
  51. &ulCount, &m_ConnFolderpidl, NULL);
  52. if (SUCCEEDED(m_HrClassState))
  53. {
  54. //
  55. // Now we have the pidl for the Connections Folder
  56. //
  57. m_HrClassState = m_pDesktopFolder->BindToObject(m_ConnFolderpidl, NULL, IID_IShellFolder,
  58. (LPVOID*)(&m_pConnectionsFolder));
  59. }
  60. }
  61. }
  62. }
  63. CLoadConnFolder::~CLoadConnFolder()
  64. {
  65. if (m_pConnectionsFolder)
  66. {
  67. m_pConnectionsFolder->Release();
  68. m_pConnectionsFolder = NULL;
  69. }
  70. if (m_pDesktopFolder)
  71. {
  72. m_pDesktopFolder->Release();
  73. m_pDesktopFolder = NULL;
  74. }
  75. if (m_ConnFolderpidl)
  76. {
  77. LPMALLOC pMalloc;
  78. HRESULT hr = SHGetMalloc(&pMalloc);
  79. if (SUCCEEDED(hr))
  80. {
  81. pMalloc->Free(m_ConnFolderpidl);
  82. pMalloc->Release();
  83. m_ConnFolderpidl = NULL;
  84. }
  85. }
  86. if (m_CoInit)
  87. {
  88. CoUninitialize();
  89. }
  90. m_HrClassState = S_FALSE;
  91. }
  92. HRESULT CLoadConnFolder::HrLaunchConnFolder()
  93. {
  94. SHELLEXECUTEINFO sei;
  95. HRESULT hr = S_OK;
  96. if (NULL != m_ConnFolderpidl)
  97. {
  98. ZeroMemory(&sei, sizeof(sei));
  99. sei.cbSize = sizeof(sei);
  100. sei.fMask = SEE_MASK_IDLIST | SEE_MASK_CLASSNAME;
  101. sei.lpIDList = m_ConnFolderpidl;
  102. sei.lpClass = TEXT("folder");
  103. sei.hwnd = NULL; //lpcmi->hwnd;
  104. sei.nShow = SW_SHOWNORMAL;
  105. sei.lpVerb = TEXT("open");
  106. if (!ShellExecuteEx(&sei))
  107. {
  108. hr = HRESULT_FROM_WIN32(GetLastError());
  109. }
  110. }
  111. return hr;
  112. }