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.

175 lines
5.2 KiB

  1. #ifndef _CMMN_H_
  2. #define _CMMN_H_
  3. #include "namellst.h"
  4. #include "mischlpr.h"
  5. #include <objbase.h>
  6. #include <dbt.h>
  7. #include <cfgmgr32.h>
  8. #include <devioctl.h>
  9. #define MAX_SURPRISEREMOVALFN 50
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //
  12. extern const GUID guidVolumeClass;
  13. extern const GUID guidDiskClass;
  14. extern const GUID guidCdRomClass;
  15. extern const GUID guidImagingDeviceClass;
  16. extern const GUID guidVideoCameraClass;
  17. extern const GUID guidInvalid;
  18. ///////////////////////////////////////////////////////////////////////////////
  19. //
  20. class CHandleNotifTarget
  21. {
  22. public:
  23. virtual HRESULT HNTHandleEvent(DEV_BROADCAST_HANDLE* pdbh,
  24. DWORD dwEventType) = 0;
  25. HRESULT HNTInitSurpriseRemoval();
  26. BOOL HNTIsSurpriseRemovalAware();
  27. CHandleNotifTarget();
  28. virtual ~CHandleNotifTarget();
  29. private:
  30. BOOL _fSurpriseRemovalAware;
  31. };
  32. enum HWEDLIST
  33. {
  34. HWEDLIST_INVALID = -1,
  35. HWEDLIST_HANDLENOTIF,
  36. HWEDLIST_VOLUME,
  37. HWEDLIST_DISK,
  38. HWEDLIST_MTPT,
  39. HWEDLIST_MISCDEVINTF,
  40. HWEDLIST_MISCDEVNODE,
  41. HWEDLIST_ADVISECLIENT,
  42. HWEDLIST_COUNT_OF_LISTS, //always last, not a list
  43. };
  44. class CHWEventDetectorHelper
  45. {
  46. public:
  47. static HRESULT Init();
  48. static HRESULT Cleanup();
  49. static void TraceDiagnosticMsg(LPTSTR pszMsg, ...);
  50. static HRESULT CheckDiagnosticAppPresence();
  51. static HRESULT SetServiceStatusHandle(SERVICE_STATUS_HANDLE ssh);
  52. static HRESULT CreateLists();
  53. static HRESULT DeleteLists();
  54. static HRESULT FillLists();
  55. static HRESULT EmptyLists();
  56. static HRESULT GetList(HWEDLIST hwedlist, CNamedElemList** ppnel);
  57. static HRESULT RegisterDeviceNotification(PVOID pvNotificationFilter,
  58. HDEVNOTIFY* phdevnotify, BOOL fAllInterfaceClasses);
  59. static HRESULT InitDockState();
  60. static HRESULT DockStateChanged(BOOL* pfDockStateChanged);
  61. static HRESULT GetImpersonateEveryone(class CImpersonateEveryone** ppieo);
  62. #ifdef DEBUG
  63. public:
  64. static void _DbgAssertValidState();
  65. #endif
  66. public:
  67. static BOOL _fDiagnosticAppPresent;
  68. private:
  69. static DWORD _dwDiagAppLastCheck;
  70. static SERVICE_STATUS_HANDLE _ssh;
  71. static BOOL _fListCreated;
  72. static CNamedElemList* _rgpnel[];
  73. static DWORD _cpnel;
  74. static BOOL _fDocked;
  75. static CImpersonateEveryone* _pieo;
  76. static CCriticalSection _cs;
  77. static BOOL _fInited;
  78. };
  79. ///////////////////////////////////////////////////////////////////////////////
  80. //
  81. typedef HRESULT (*INTERFACEENUMFILTERCALLBACK)(LPCWSTR pszDeviceIntfID);
  82. class CIntfFillEnum
  83. {
  84. public:
  85. HRESULT Next(LPWSTR pszElemName, DWORD cchElemName, DWORD* pcchRequired);
  86. HRESULT _Init(const GUID* pguidInterface, INTERFACEENUMFILTERCALLBACK iecb);
  87. public:
  88. CIntfFillEnum();
  89. ~CIntfFillEnum();
  90. private:
  91. LPWSTR _pszNextInterface;
  92. LPWSTR _pszDeviceInterface;
  93. INTERFACEENUMFILTERCALLBACK _iecb;
  94. };
  95. ///////////////////////////////////////////////////////////////////////////////
  96. //
  97. HRESULT _DeviceInstIsRemovable(DEVINST devinst, BOOL* pfRemovable);
  98. HANDLE _GetDeviceHandle(LPCTSTR psz, DWORD dwDesiredAccess);
  99. void _CloseDeviceHandle(HANDLE hDevice);
  100. HRESULT _GetDeviceNumberInfoFromHandle(HANDLE h, DEVICE_TYPE* pdevtype,
  101. ULONG* pulDeviceNumber, ULONG* pulPartitionNumber);
  102. HRESULT _GetVolumeName(LPCWSTR pszDeviceID, LPWSTR pszVolumeName,
  103. DWORD cchVolumeName);
  104. HRESULT _GetDeviceIDFromMtPtName(LPCWSTR pszMtPt, LPWSTR pszDeviceID,
  105. DWORD cchDeviceID);
  106. HRESULT _GetDeviceIDFromHDevNotify(HDEVNOTIFY hdevnotify,
  107. LPWSTR pszDeviceID, DWORD cchDeviceID, DWORD* pcchRequired);
  108. HRESULT _GetDeviceID(LPCWSTR pszName, LPWSTR pszDeviceID,
  109. DWORD cchDeviceID);
  110. HRESULT _GetHWDeviceInstFromDeviceOrVolumeIntfID(LPCWSTR pszDeviceIntfID,
  111. class CHWDeviceInst** pphwdevinst, CNamedElem** ppelemToRelease);
  112. HRESULT _GetHWDeviceInstFromVolumeIntfID(LPCWSTR pszDeviceIntfID,
  113. CHWDeviceInst** pphwdevinst, CNamedElem** ppelemToRelease);
  114. HRESULT _GetHWDeviceInstFromDeviceIntfID(LPCWSTR pszDeviceIntfID,
  115. CHWDeviceInst** pphwdevinst, CNamedElem** ppelemToRelease);
  116. HRESULT _GetHWDeviceInstFromDeviceNode(LPCWSTR pszDeviceNode,
  117. CHWDeviceInst** pphwdevinst, CNamedElem** ppelemToRelease);
  118. HRESULT _GetVolume(LPCWSTR pszVolume, class CVolume** ppvol);
  119. HRESULT _GetAltDeviceID(LPCWSTR pszDeviceID, LPWSTR pszDeviceIDAlt,
  120. DWORD cchDeviceIDAlt);
  121. HRESULT _CoTaskMemCopy(LPCWSTR pszSrc, LPWSTR* ppszDest);
  122. void _CoTaskMemFree(void* pv);
  123. HRESULT DupString(LPCWSTR pszSrc, LPWSTR* ppszDest);
  124. HRESULT _GetDeviceInstance(LPCWSTR pszDeviceIntfID, DEVINST* pdevinst,
  125. GUID* pguidInterface);
  126. HRESULT _GetDeviceInstanceFromDevNode(LPCWSTR pszDeviceNode,
  127. DEVINST* pdevinst);
  128. HRESULT _MachineIsDocked(BOOL* pfDocked);
  129. HRESULT _BuildMoniker(LPCWSTR pszEventHandler, REFCLSID rclsid,
  130. DWORD dwSessionID, IMoniker** ppmoniker);
  131. ///////////////////////////////////////////////////////////////////////////////
  132. //
  133. #define DIAGNOSTIC(__allargs) { if (CHWEventDetectorHelper::_fDiagnosticAppPresent) \
  134. { CHWEventDetectorHelper::TraceDiagnosticMsg __allargs ; } else \
  135. { ; } }
  136. #endif //_CMMN_H_