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.

187 lines
3.7 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. ////////////////////
  17. // Reference Count
  18. class RefCount
  19. {
  20. private:
  21. LONG m_cRef;
  22. public:
  23. RefCount();
  24. // Virtual destructor defers to destructor of derived class.
  25. virtual ~RefCount();
  26. // IUnknown methods
  27. ULONG STDMETHODCALLTYPE AddRef(void);
  28. ULONG STDMETHODCALLTYPE Release(void);
  29. };
  30. //////////////////////
  31. // Notification Sink
  32. class CNotify
  33. {
  34. private:
  35. DWORD m_dwCookie;
  36. IUnknown * m_pUnk;
  37. IConnectionPoint * m_pcnp;
  38. IConnectionPointContainer * m_pcnpcnt;
  39. public:
  40. CNotify(void);
  41. ~CNotify();
  42. HRESULT Connect(IUnknown *pUnk, REFIID riid, IUnknown *pUnkN);
  43. HRESULT Disconnect(void);
  44. IUnknown * GetPunk() {return m_pUnk;}
  45. };
  46. ///////////
  47. // OBLIST
  48. #define POSITION COBNODE*
  49. struct COBNODE
  50. {
  51. POSITION pNext;
  52. void* pItem;
  53. };
  54. class COBLIST
  55. {
  56. protected:
  57. POSITION m_pHead;
  58. POSITION m_pTail;
  59. int m_cItem;
  60. virtual BOOL Compare(void* pItemToCompare, void* pComparator)
  61. { return(pItemToCompare == pComparator); }
  62. public:
  63. COBLIST() : m_pHead(NULL), m_pTail(NULL), m_cItem(0) { }
  64. virtual ~COBLIST();
  65. virtual void * RemoveAt(POSITION rPos);
  66. void EmptyList();
  67. POSITION AddTail(void* pItem);
  68. void * GetNext(POSITION& rPos);
  69. void * SafeGetFromPosition(POSITION rPos);
  70. POSITION GetPosition(void* pItem);
  71. POSITION Lookup(void* pComparator);
  72. POSITION GetHeadPosition() { return (m_pHead); }
  73. POSITION GetTailPosition() { return (m_pTail); }
  74. BOOL IsEmpty() { return (!m_pHead); }
  75. int GetItemCount() { return (m_cItem); }
  76. #ifdef DEBUG
  77. void * GetHead();
  78. void * GetTail();
  79. void * RemoveHead();
  80. void * RemoveTail();
  81. void * GetFromPosition(POSITION rPos);
  82. #else
  83. void * GetHead() { return GetFromPosition(GetHeadPosition());}
  84. void * GetTail() { return m_pTail->pItem;}
  85. void * RemoveHead() { return RemoveAt(m_pHead); }
  86. void * RemoveTail() { return RemoveAt(m_pTail); }
  87. void * GetFromPosition(POSITION rPos){return(rPos->pItem);}
  88. #endif
  89. };
  90. // Utility Functions
  91. POSITION AddNode(PVOID pv, COBLIST ** ppList);
  92. PVOID RemoveNode(POSITION * pPos, COBLIST *pList);
  93. ////////////
  94. // BSTRING
  95. class BSTRING
  96. {
  97. private:
  98. BSTR m_bstr;
  99. public:
  100. // Constructors
  101. BSTRING() {m_bstr = NULL;}
  102. inline BSTRING(LPCWSTR lpcwString);
  103. #if !defined(UNICODE)
  104. // We don't support construction from an ANSI string in the Unicode build.
  105. BSTRING(LPCSTR lpcString);
  106. #endif // !defined(UNICODE)
  107. // Destructor
  108. inline ~BSTRING();
  109. // Cast to BSTR
  110. operator BSTR() {return m_bstr;}
  111. inline LPBSTR GetLPBSTR(void);
  112. };
  113. BSTRING::BSTRING(LPCWSTR lpcwString)
  114. {
  115. if (NULL != lpcwString)
  116. {
  117. m_bstr = SysAllocString(lpcwString);
  118. //ASSERT(NULL != m_bstr);
  119. }
  120. else
  121. {
  122. m_bstr = NULL;
  123. }
  124. }
  125. BSTRING::~BSTRING()
  126. {
  127. if (NULL != m_bstr)
  128. {
  129. SysFreeString(m_bstr);
  130. }
  131. }
  132. inline LPBSTR BSTRING::GetLPBSTR(void)
  133. {
  134. //ASSERT(NULL == m_bstr);
  135. return &m_bstr;
  136. }
  137. class BTSTR
  138. {
  139. private:
  140. LPTSTR m_psz;
  141. public:
  142. BTSTR(BSTR bstr);
  143. ~BTSTR();
  144. // Cast to BSTR
  145. operator LPTSTR() {return (NULL == m_psz) ? TEXT("<null>") : m_psz;}
  146. };
  147. LPTSTR PszFromBstr(BSTR bst);
  148. #endif // _CL_UTIL_H_