Leaked source code of windows server 2003
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.

167 lines
5.1 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. virtual ~CHandleNotifTarget();
  28. };
  29. enum HWEDLIST
  30. {
  31. HWEDLIST_INVALID = -1,
  32. HWEDLIST_HANDLENOTIF,
  33. HWEDLIST_VOLUME,
  34. HWEDLIST_DISK,
  35. HWEDLIST_MTPT,
  36. HWEDLIST_MISCDEVINTF,
  37. HWEDLIST_MISCDEVNODE,
  38. HWEDLIST_ADVISECLIENT,
  39. HWEDLIST_COUNT_OF_LISTS, //always last, not a list
  40. };
  41. class CHWEventDetectorHelper
  42. {
  43. public:
  44. static HRESULT Init();
  45. static HRESULT Cleanup();
  46. static void TraceDiagnosticMsg(LPTSTR pszMsg, ...);
  47. static HRESULT CheckDiagnosticAppPresence();
  48. static HRESULT SetServiceStatusHandle(SERVICE_STATUS_HANDLE ssh);
  49. static HRESULT CreateLists();
  50. static HRESULT DeleteLists();
  51. static HRESULT FillLists();
  52. static HRESULT EmptyLists();
  53. static HRESULT GetList(HWEDLIST hwedlist, CNamedElemList** ppnel);
  54. static HRESULT RegisterDeviceNotification(PVOID pvNotificationFilter,
  55. HDEVNOTIFY* phdevnotify, BOOL fAllInterfaceClasses);
  56. static HRESULT InitDockState();
  57. static HRESULT DockStateChanged(BOOL* pfDockStateChanged);
  58. static HRESULT GetImpersonateEveryone(class CImpersonateEveryone** ppieo);
  59. #ifdef DEBUG
  60. public:
  61. static void _DbgAssertValidState();
  62. #endif
  63. public:
  64. static BOOL _fDiagnosticAppPresent;
  65. private:
  66. static DWORD _dwDiagAppLastCheck;
  67. static SERVICE_STATUS_HANDLE _ssh;
  68. static BOOL _fListCreated;
  69. static CNamedElemList* _rgpnel[];
  70. static DWORD _cpnel;
  71. static BOOL _fDocked;
  72. static CImpersonateEveryone* _pieo;
  73. static CCritSect _cs;
  74. static BOOL _fInited;
  75. };
  76. ///////////////////////////////////////////////////////////////////////////////
  77. //
  78. typedef HRESULT (*INTERFACEENUMFILTERCALLBACK)(LPCWSTR pszDeviceIntfID);
  79. class CIntfFillEnum
  80. {
  81. public:
  82. HRESULT Next(LPWSTR pszElemName, DWORD cchElemName, DWORD* pcchRequired);
  83. HRESULT _Init(const GUID* pguidInterface, INTERFACEENUMFILTERCALLBACK iecb);
  84. public:
  85. CIntfFillEnum();
  86. ~CIntfFillEnum();
  87. private:
  88. LPWSTR _pszNextInterface;
  89. LPWSTR _pszDeviceInterface;
  90. INTERFACEENUMFILTERCALLBACK _iecb;
  91. };
  92. ///////////////////////////////////////////////////////////////////////////////
  93. //
  94. HRESULT _DeviceInstIsRemovable(DEVINST devinst, BOOL* pfRemovable);
  95. HANDLE _GetDeviceHandle(LPCTSTR psz, DWORD dwDesiredAccess);
  96. void _CloseDeviceHandle(HANDLE hDevice);
  97. HRESULT _GetDeviceNumberInfoFromHandle(HANDLE h, DEVICE_TYPE* pdevtype,
  98. ULONG* pulDeviceNumber, ULONG* pulPartitionNumber);
  99. HRESULT _GetVolumeName(LPCWSTR pszDeviceID, LPWSTR pszVolumeName,
  100. DWORD cchVolumeName);
  101. HRESULT _GetDeviceIDFromMtPtName(LPCWSTR pszMtPt, LPWSTR pszDeviceID,
  102. DWORD cchDeviceID);
  103. HRESULT _GetDeviceID(LPCWSTR pszName, LPWSTR pszDeviceID,
  104. DWORD cchDeviceID);
  105. HRESULT _GetHWDeviceInstFromDeviceOrVolumeIntfID(LPCWSTR pszDeviceIntfID,
  106. class CHWDeviceInst** pphwdevinst, CNamedElem** ppelemToRelease);
  107. HRESULT _GetHWDeviceInstFromVolumeIntfID(LPCWSTR pszDeviceIntfID,
  108. CHWDeviceInst** pphwdevinst, CNamedElem** ppelemToRelease);
  109. HRESULT _GetHWDeviceInstFromDeviceIntfID(LPCWSTR pszDeviceIntfID,
  110. CHWDeviceInst** pphwdevinst, CNamedElem** ppelemToRelease);
  111. HRESULT _GetHWDeviceInstFromDeviceNode(LPCWSTR pszDeviceNode,
  112. CHWDeviceInst** pphwdevinst, CNamedElem** ppelemToRelease);
  113. HRESULT _GetAltDeviceID(LPCWSTR pszDeviceID, LPWSTR pszDeviceIDAlt,
  114. DWORD cchDeviceIDAlt);
  115. HRESULT _CoTaskMemCopy(LPCWSTR pszSrc, LPWSTR* ppszDest);
  116. void _CoTaskMemFree(void* pv);
  117. HRESULT DupString(LPCWSTR pszSrc, LPWSTR* ppszDest);
  118. HRESULT _GetDeviceInstance(LPCWSTR pszDeviceIntfID, DEVINST* pdevinst,
  119. GUID* pguidInterface);
  120. HRESULT _GetDeviceInstanceFromDevNode(LPCWSTR pszDeviceNode,
  121. DEVINST* pdevinst);
  122. HRESULT _MachineIsDocked(BOOL* pfDocked);
  123. HRESULT _BuildMoniker(LPCWSTR pszEventHandler, REFCLSID rclsid,
  124. DWORD dwSessionID, IMoniker** ppmoniker);
  125. ///////////////////////////////////////////////////////////////////////////////
  126. //
  127. #define DIAGNOSTIC(__allargs) { if (CHWEventDetectorHelper::_fDiagnosticAppPresent) \
  128. { CHWEventDetectorHelper::TraceDiagnosticMsg __allargs ; } else \
  129. { ; } }
  130. #endif //_CMMN_H_