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.

142 lines
4.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // HardwareDevices Registration
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #ifndef _REGNOTIF_H
  5. #define _REGNOTIF_H
  6. #include "unk.h"
  7. #include "namellst.h"
  8. #include <shpriv.h>
  9. extern const CLSID CLSID_HardwareDevices;
  10. class CHardwareDevicesImpl : public CCOMBase, public IHardwareDevices
  11. {
  12. public:
  13. // Interface IHardwareDevices
  14. STDMETHODIMP EnumVolumes(DWORD dwFlags, IHardwareDevicesVolumesEnum** ppenum);
  15. STDMETHODIMP EnumMountPoints(IHardwareDevicesMountPointsEnum** ppenum);
  16. STDMETHODIMP EnumDevices(IHardwareDevicesEnum** ppenum);
  17. STDMETHODIMP Advise(DWORD dwProcessID, ULONG_PTR hThread,
  18. ULONG_PTR pfctCallback, DWORD* pdwToken);
  19. STDMETHODIMP Unadvise(DWORD dwToken);
  20. public:
  21. static HRESULT _AdviseVolumeArrivedOrUpdated(
  22. VOLUMEINFO2* pvolinfo2, LPCWSTR pszMtPts, DWORD cchMtPts, BOOL fAdded);
  23. static HRESULT _AdviseVolumeRemoved(LPCWSTR pszDeviceIDVolume,
  24. LPCWSTR pszMtPts, DWORD cchMtPts);
  25. static HRESULT _AdviseMountPointHelper(LPCWSTR pszMtPt,
  26. LPCWSTR pszDeviceIDVolume, BOOL fAdded);
  27. static HRESULT _AdviseVolumeMountingEvent(LPCWSTR pszDeviceIDVolume,
  28. DWORD dwEvent);
  29. static HRESULT _AdviseCheckClients(void);
  30. static HRESULT _AdviseDeviceArrivedOrRemoved(LPCWSTR pszDeviceIntfID,
  31. GUID* pguidInterface, DWORD dwDeviceFlags, LPCWSTR pszEventType);
  32. public:
  33. CHardwareDevicesImpl();
  34. ~CHardwareDevicesImpl();
  35. private:
  36. static DWORD _chwdevcb;
  37. static LONG _lAdviseToken;
  38. };
  39. typedef CUnkTmpl<CHardwareDevicesImpl> CHardwareDevices;
  40. ///////////////////////////////////////////////////////////////////////////////
  41. //
  42. class CHardwareDevicesEnumImpl : public CCOMBase, public IHardwareDevicesEnum
  43. {
  44. public:
  45. // Interface IHardwareDevicesEnum
  46. STDMETHODIMP Next(
  47. LPWSTR* ppszDeviceID,
  48. GUID* pguidDeviceID);
  49. public:
  50. CHardwareDevicesEnumImpl();
  51. ~CHardwareDevicesEnumImpl();
  52. };
  53. typedef CUnkTmpl<CHardwareDevicesEnumImpl> CHardwareDevicesEnum;
  54. ///////////////////////////////////////////////////////////////////////////////
  55. //
  56. class CHardwareDevicesVolumesEnumImpl : public CCOMBase,
  57. public IHardwareDevicesVolumesEnum
  58. {
  59. public:
  60. // Interface IHardwareDevicesVolumesEnum
  61. STDMETHODIMP Next(VOLUMEINFO* pvolinfo);
  62. public: // for CHardwareDevicesImpl usage only
  63. HRESULT _Init(DWORD dwFlags);
  64. public:
  65. CHardwareDevicesVolumesEnumImpl();
  66. ~CHardwareDevicesVolumesEnumImpl();
  67. private:
  68. class CNamedElemEnum* _penum;
  69. DWORD _dwFlags;
  70. };
  71. typedef CUnkTmpl<CHardwareDevicesVolumesEnumImpl> CHardwareDevicesVolumesEnum;
  72. ///////////////////////////////////////////////////////////////////////////////
  73. //
  74. class CHardwareDevicesMountPointsEnumImpl : public CCOMBase,
  75. public IHardwareDevicesMountPointsEnum
  76. {
  77. public:
  78. // Interface IHardwareDevicesMountPointsEnum
  79. STDMETHODIMP Next(
  80. LPWSTR* ppszMountPoint, // "c:\", or "d:\MountFolder\"
  81. LPWSTR* ppszDeviceIDVolume);// \\?\STORAGE#Volume#...{...GUID...}
  82. public: // for CHardwareDevicesImpl usage only
  83. HRESULT _Init();
  84. public:
  85. CHardwareDevicesMountPointsEnumImpl();
  86. ~CHardwareDevicesMountPointsEnumImpl();
  87. private:
  88. class CNamedElemEnum* _penum;
  89. };
  90. typedef CUnkTmpl<CHardwareDevicesMountPointsEnumImpl>
  91. CHardwareDevicesMountPointsEnum;
  92. ///////////////////////////////////////////////////////////////////////////////
  93. //
  94. class CAdviseClient : public CNamedElem
  95. {
  96. public:
  97. HRESULT Init(LPCWSTR pszElemName);
  98. HRESULT _Init(DWORD dwProcessID, ULONG_PTR hThread,
  99. ULONG_PTR pfctCallback);
  100. HRESULT _Cleanup();
  101. HRESULT WriteMemoryChunkInOtherProcess(SHHARDWAREEVENT* pshhe,
  102. DWORD cbSize, void** ppv);
  103. HRESULT QueueUserAPC(void* pv);
  104. HRESULT IsProcessStillAlive(void);
  105. protected:
  106. CAdviseClient();
  107. ~CAdviseClient();
  108. public:
  109. static HRESULT Create(CNamedElem** ppelem);
  110. private:
  111. PAPCFUNC _pfct;
  112. HANDLE _hProcess;
  113. HANDLE _hThread;
  114. };
  115. #endif // _REGNOTIF_H