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.

191 lines
5.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // sens.h
  7. //
  8. // Definition of classes needed for to handle SENS notifications.
  9. //
  10. // 10/9/2001 annah Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #pragma once
  14. #include <coguid.h>
  15. #include <sens.h>
  16. #include <sensevts.h>
  17. #include <eventsys.h>
  18. //----------------------------------------------------------------------------
  19. // Information used to create the AU subscriptions with ISensLogon
  20. //----------------------------------------------------------------------------
  21. static struct { GUID MethodGuid; LPCWSTR pszMethodName; } g_oLogonSubscription = {
  22. // Declares the guid and name for our Logon method.
  23. // L"{2f519218-754d-4cfe-8daa-5215cd0de0eb}",
  24. { 0x2f519218, 0x754d, 0x4cfe, {0x8d, 0xaa, 0x52, 0x15, 0xcd, 0x0d, 0xe0, 0xeb} },
  25. L"Logon"
  26. };
  27. #define SUBSCRIPTION_NAME_TEXT L"WU Autoupdate"
  28. #define SUBSCRIPTION_DESCRIPTION_TEXT L"WU Autoupdate Notification subscription"
  29. class CBstrTable {
  30. void Cleanup()
  31. {
  32. SafeFreeBSTR(m_bstrLogonMethodGuid);
  33. SafeFreeBSTR(m_bstrLogonMethodName);
  34. SafeFreeBSTR(m_bstrSubscriptionName);
  35. SafeFreeBSTR(m_bstrSubscriptionDescription);
  36. SafeFreeBSTR(m_bstrSensEventClassGuid);
  37. SafeFreeBSTR(m_bstrSensLogonGuid);
  38. }
  39. public:
  40. BSTR m_bstrLogonMethodGuid;
  41. BSTR m_bstrLogonMethodName;
  42. BSTR m_bstrSubscriptionName;
  43. BSTR m_bstrSubscriptionDescription;
  44. BSTR m_bstrSensEventClassGuid;
  45. BSTR m_bstrSensLogonGuid;
  46. CBstrTable() :
  47. m_bstrLogonMethodGuid(NULL),
  48. m_bstrLogonMethodName(NULL),
  49. m_bstrSubscriptionName(NULL),
  50. m_bstrSubscriptionDescription(NULL),
  51. m_bstrSensEventClassGuid(NULL),
  52. m_bstrSensLogonGuid(NULL) { }
  53. ~CBstrTable() { Cleanup(); }
  54. HRESULT Initialize();
  55. };
  56. //----------------------------------------------------------------------------
  57. // Prototypes for functions used externally
  58. //----------------------------------------------------------------------------
  59. HRESULT ActivateSensLogonNotification();
  60. HRESULT DeactivateSensLogonNotification();
  61. //----------------------------------------------------------------------------
  62. // CSimpleIUnknown
  63. //
  64. // Light-weight class that implements the basic COM methods.
  65. //----------------------------------------------------------------------------
  66. template<class T> class CSimpleIUnknown : public T
  67. {
  68. public:
  69. // IUnknown Methods
  70. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
  71. ULONG _stdcall AddRef(void);
  72. ULONG _stdcall Release(void);
  73. protected:
  74. CSimpleIUnknown() : m_refs(1) {}; // always start with one ref count!
  75. LONG m_refs;
  76. };
  77. template<class T> STDMETHODIMP CSimpleIUnknown<T>::QueryInterface(REFIID iid, void** ppvObject)
  78. {
  79. HRESULT hr = S_OK;
  80. *ppvObject = NULL;
  81. if ((iid == IID_IUnknown) || (iid == _uuidof(T)))
  82. {
  83. *ppvObject = static_cast<T *> (this);
  84. (static_cast<IUnknown *>(*ppvObject))->AddRef();
  85. }
  86. else
  87. {
  88. hr = E_NOINTERFACE;
  89. }
  90. return hr;
  91. }
  92. template<class T> ULONG CSimpleIUnknown<T>::AddRef()
  93. {
  94. ULONG newrefs = InterlockedIncrement(&m_refs);
  95. return newrefs;
  96. }
  97. template<class T> ULONG CSimpleIUnknown<T>::Release()
  98. {
  99. ULONG newrefs = InterlockedDecrement(&m_refs);
  100. if (newrefs == 0)
  101. {
  102. DEBUGMSG("Deleting object due to ref count hitting 0");
  103. delete this;
  104. return 0;
  105. }
  106. return m_refs;
  107. }
  108. //----------------------------------------------------------------------------
  109. // CLogonNotification
  110. //
  111. // This is the class that will be used to subscribe to SENS. As such,
  112. // it needs to implement the IDispatch interface and the ISensLogon methods.
  113. //
  114. // ISensLogon already inherits from IUnknown and IDispatch, so there's no
  115. // need to make CLogonNotification to do this also.
  116. //
  117. //----------------------------------------------------------------------------
  118. class CLogonNotification : public CSimpleIUnknown<ISensLogon>
  119. {
  120. public:
  121. CLogonNotification() :
  122. m_EventSystem( NULL ),
  123. m_TypeLib( NULL ),
  124. m_TypeInfo( NULL ),
  125. m_fSubscribed( FALSE ),
  126. m_oBstrTable(NULL) {}
  127. ~CLogonNotification() { Cleanup(); }
  128. HRESULT Initialize();
  129. private:
  130. IEventSystem *m_EventSystem;
  131. ITypeLib *m_TypeLib;
  132. ITypeInfo *m_TypeInfo;
  133. CBstrTable *m_oBstrTable;
  134. BOOL m_fSubscribed;
  135. void Cleanup();
  136. HRESULT SubscribeMethod(const BSTR bstrMethodName, const BSTR bstrMethodGuid);
  137. HRESULT UnsubscribeAllMethods();
  138. HRESULT CheckLocalSystem();
  139. public:
  140. // Other IUnknown methods come from CSimpleIUnknown
  141. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject);
  142. // IDispatch methods (needed for SENS subscription)
  143. HRESULT STDMETHODCALLTYPE GetTypeInfoCount(unsigned int FAR* pctinfo);
  144. HRESULT STDMETHODCALLTYPE GetTypeInfo(unsigned int iTInfo, LCID lcid, ITypeInfo FAR* FAR* ppTInfo);
  145. HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgDispId);
  146. HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr);
  147. // ISensLogon methods -- we will be using only Logon & Logoff
  148. HRESULT STDMETHODCALLTYPE DisplayLock( BSTR UserName );
  149. HRESULT STDMETHODCALLTYPE DisplayUnlock( BSTR UserName );
  150. HRESULT STDMETHODCALLTYPE StartScreenSaver( BSTR UserName );
  151. HRESULT STDMETHODCALLTYPE StopScreenSaver( BSTR UserName );
  152. HRESULT STDMETHODCALLTYPE Logon( BSTR UserName );
  153. HRESULT STDMETHODCALLTYPE Logoff( BSTR UserName );
  154. HRESULT STDMETHODCALLTYPE StartShell( BSTR UserName );
  155. };