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.

192 lines
3.9 KiB

  1. //****************************************************************************
  2. // Module: NMCHAT.EXE
  3. // File: CLUTIL.H
  4. // Content:
  5. //
  6. //
  7. // Copyright (c) Microsoft Corporation 1997
  8. //
  9. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  10. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  11. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  12. // PARTICULAR PURPOSE.
  13. //****************************************************************************
  14. #ifndef _CL_UTIL_H_
  15. #define _CL_UTIL_H_
  16. // Reference Count
  17. class RefCount
  18. {
  19. private:
  20. LONG m_cRef;
  21. public:
  22. RefCount();
  23. // Virtual destructor defers to destructor of derived class.
  24. virtual ~RefCount();
  25. // IUnknown methods
  26. ULONG STDMETHODCALLTYPE AddRef(void);
  27. ULONG STDMETHODCALLTYPE Release(void);
  28. };
  29. //////////////////////
  30. // Notification Sink
  31. class CNotify
  32. {
  33. private:
  34. DWORD m_dwCookie;
  35. IUnknown * m_pUnk;
  36. IConnectionPoint * m_pcnp;
  37. IConnectionPointContainer * m_pcnpcnt;
  38. public:
  39. CNotify(void);
  40. ~CNotify();
  41. HRESULT Connect(IUnknown *pUnk, REFIID riid, IUnknown *pUnkN);
  42. HRESULT Disconnect(void);
  43. IUnknown * GetPunk() {return m_pUnk;}
  44. };
  45. ///////////
  46. // OBLIST
  47. #define POSITION COBNODE*
  48. struct COBNODE
  49. {
  50. POSITION pNext;
  51. void* pItem;
  52. };
  53. class COBLIST
  54. {
  55. protected:
  56. POSITION m_pHead;
  57. POSITION m_pTail;
  58. int m_cItem;
  59. virtual BOOL Compare(void* pItemToCompare, void* pComparator)
  60. { return(pItemToCompare == pComparator); }
  61. public:
  62. COBLIST() : m_pHead(NULL), m_pTail(NULL), m_cItem(0) { }
  63. virtual ~COBLIST();
  64. virtual void * RemoveAt(POSITION rPos);
  65. void EmptyList();
  66. POSITION AddTail(void* pItem);
  67. void * GetNext(POSITION& rPos);
  68. void * SafeGetFromPosition(POSITION rPos);
  69. POSITION GetPosition(void* pItem);
  70. POSITION Lookup(void* pComparator);
  71. POSITION GetHeadPosition() { return (m_pHead); }
  72. POSITION GetTailPosition() { return (m_pTail); }
  73. BOOL IsEmpty() { return (!m_pHead); }
  74. int GetItemCount() { return (m_cItem); }
  75. #ifdef DEBUG
  76. void * GetHead();
  77. void * GetTail();
  78. void * RemoveHead();
  79. void * RemoveTail();
  80. void * GetFromPosition(POSITION rPos);
  81. #else
  82. void * GetHead() { return GetFromPosition(GetHeadPosition());}
  83. void * GetTail() { return m_pTail->pItem;}
  84. void * RemoveHead() { return RemoveAt(m_pHead); }
  85. void * RemoveTail() { return RemoveAt(m_pTail); }
  86. void * GetFromPosition(POSITION rPos){return(rPos->pItem);}
  87. #endif
  88. };
  89. // Utility Functions
  90. POSITION AddNode(PVOID pv, COBLIST ** ppList);
  91. PVOID RemoveNode(POSITION * pPos, COBLIST *pList);
  92. ////////////
  93. // BSTRING
  94. class BSTRING
  95. {
  96. private:
  97. BSTR m_bstr;
  98. public:
  99. // Constructors
  100. BSTRING() {m_bstr = NULL;}
  101. inline BSTRING(LPCWSTR lpcwString);
  102. #if !defined(UNICODE)
  103. // We don't support construction from an ANSI string in the Unicode build.
  104. BSTRING(LPCSTR lpcString);
  105. #endif // !defined(UNICODE)
  106. // Destructor
  107. inline ~BSTRING();
  108. // Cast to BSTR
  109. operator BSTR() {return m_bstr;}
  110. inline LPBSTR GetLPBSTR(void);
  111. };
  112. BSTRING::BSTRING(LPCWSTR lpcwString)
  113. {
  114. if (NULL != lpcwString)
  115. {
  116. m_bstr = SysAllocString(lpcwString);
  117. //ASSERT(NULL != m_bstr);
  118. }
  119. else
  120. {
  121. m_bstr = NULL;
  122. }
  123. }
  124. BSTRING::~BSTRING()
  125. {
  126. if (NULL != m_bstr)
  127. {
  128. SysFreeString(m_bstr);
  129. }
  130. }
  131. inline LPBSTR BSTRING::GetLPBSTR(void)
  132. {
  133. //ASSERT(NULL == m_bstr);
  134. return &m_bstr;
  135. }
  136. class BTSTR
  137. {
  138. private:
  139. LPTSTR m_psz;
  140. public:
  141. BTSTR(BSTR bstr);
  142. ~BTSTR();
  143. // Cast to BSTR
  144. operator LPTSTR() {return (NULL == m_psz) ? TEXT("<null>") : m_psz;}
  145. };
  146. LPTSTR PszFromBstr(BSTR bst);
  147. HRESULT BSTR_to_LPTSTR(LPTSTR *ppsz, BSTR bstr);
  148. HRESULT NmAdvise(IUnknown* pUnkCP, IUnknown* pUnk, const IID& iid, LPDWORD pdw);
  149. HRESULT NmUnadvise(IUnknown* pUnkCP, const IID& iid, DWORD dw);
  150. #endif // _CL_UTIL_H_