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.

156 lines
3.7 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: API.c
  7. //
  8. // Contents:
  9. //
  10. // APIs: MMCPropertyChangeNotify
  11. //
  12. // History: 10/15/1996 RaviR Created
  13. //____________________________________________________________________________
  14. //
  15. #include <wtypes.h>
  16. #include "objbase.h"
  17. #ifndef DECLSPEC_UUID
  18. #if _MSC_VER >= 1100
  19. #define DECLSPEC_UUID(x) __declspec(uuid(x))
  20. #else
  21. #define DECLSPEC_UUID(x)
  22. #endif
  23. #endif
  24. #include "commctrl.h" // for LV_ITEMW needed by ndmgrpriv.h
  25. #include "mmc.h"
  26. #include "ndmgr.h"
  27. #include "ndmgrpriv.h"
  28. #include "mmcptrs.h"
  29. #include "ndmgrp.h"
  30. #include "amcmsgid.h"
  31. HRESULT MMCPropertyChangeNotify(LONG_PTR lNotifyHandle, LPARAM lParam)
  32. {
  33. // Note - the property sheet is in a different thread than the console.
  34. // So init COM.
  35. HRESULT hr = CoInitialize(NULL);
  36. if (SUCCEEDED(hr))
  37. {
  38. LPPROPERTYSHEETNOTIFY ppsn;
  39. hr = CoCreateInstance (CLSID_NodeManager, NULL, CLSCTX_INPROC,
  40. IID_IPropertySheetNotify,
  41. reinterpret_cast<void **>(&ppsn));
  42. if (SUCCEEDED(hr))
  43. {
  44. LPPROPERTYNOTIFYINFO ppni = reinterpret_cast<LPPROPERTYNOTIFYINFO>(lNotifyHandle);
  45. ppsn->Notify (ppni, lParam);
  46. ppsn->Release();
  47. }
  48. // Uninit COM
  49. CoUninitialize();
  50. }
  51. return (hr);
  52. }
  53. HRESULT MMCPropertyHelp (LPOLESTR pszHelpTopic)
  54. {
  55. // find the MMC main window for this process
  56. HWND hwndFrame = NULL;
  57. const DWORD dwCurrentPid = GetCurrentProcessId();
  58. while (1)
  59. {
  60. // find an MMC frame window
  61. hwndFrame = FindWindowEx (NULL, hwndFrame, MAINFRAME_CLASS_NAME, NULL);
  62. if (hwndFrame == NULL)
  63. break;
  64. // found a frame, is it on this process?
  65. DWORD dwWindowPid;
  66. GetWindowThreadProcessId (hwndFrame, &dwWindowPid);
  67. if (dwCurrentPid == dwWindowPid)
  68. break;
  69. }
  70. if (hwndFrame == NULL)
  71. return (E_UNEXPECTED);
  72. return ((HRESULT) SendMessage (hwndFrame, MMC_MSG_SHOW_SNAPIN_HELP_TOPIC,
  73. NULL, reinterpret_cast<LPARAM>(pszHelpTopic)));
  74. }
  75. HRESULT MMCFreeNotifyHandle(LONG_PTR lNotifyHandle)
  76. {
  77. if (lNotifyHandle == NULL)
  78. return E_INVALIDARG;
  79. LPPROPERTYNOTIFYINFO ppni =
  80. reinterpret_cast<LPPROPERTYNOTIFYINFO>(lNotifyHandle);
  81. BOOL bResult;
  82. if ((bResult = IsBadReadPtr(ppni, sizeof(PROPERTYNOTIFYINFO))) == FALSE)
  83. ::GlobalFree(ppni);
  84. return ((bResult == FALSE) ? S_OK : E_FAIL);
  85. }
  86. HRESULT MMCIsMTNodeValid(void* pMTNode, BOOL bReset)
  87. {
  88. HRESULT hr = S_FALSE;
  89. HWND hWnd = NULL;
  90. DWORD dwPid = 0;
  91. DWORD dwTid = 0;
  92. if (pMTNode == NULL)
  93. return hr;
  94. while (1)
  95. {
  96. hWnd = ::FindWindowEx(NULL, hWnd, DATAWINDOW_CLASS_NAME, NULL);
  97. // No windows found
  98. if (hWnd == NULL)
  99. break;
  100. // Check if the window belongs to the current process
  101. dwTid = ::GetWindowThreadProcessId(hWnd, &dwPid);
  102. if (dwPid != ::GetCurrentProcessId())
  103. continue;
  104. // Get the extra bytes and compare the data objects
  105. if (GetClassLong(hWnd, GCL_CBWNDEXTRA) != WINDOW_DATA_SIZE)
  106. break;
  107. DataWindowData* pData = GetDataWindowData (hWnd);
  108. if (pData == NULL)
  109. break;
  110. if (pData->lpMasterNode == reinterpret_cast<LONG_PTR>(pMTNode))
  111. {
  112. // clear the data out if the user requests it
  113. if (bReset)
  114. pData->lpMasterNode = NULL;
  115. hr = S_OK;
  116. break;
  117. }
  118. }
  119. return hr;
  120. }