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.

159 lines
3.3 KiB

  1. //****************************************************************************
  2. //
  3. // BLClient sample for Microsoft Messenger SDK
  4. //
  5. // Module: BLClient.exe
  6. // File: clUtil.h
  7. // Content: Usefull clases for COM and Connection points
  8. //
  9. //
  10. // Copyright (c) Microsoft Corporation 1997-1998
  11. //
  12. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  13. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  14. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  15. // PARTICULAR PURPOSE.
  16. //****************************************************************************
  17. #ifndef _CL_UTIL_H_
  18. #define _CL_UTIL_H_
  19. class CIEMsgAb;
  20. #include <docobj.h>
  21. //****************************************************************************
  22. //
  23. // CLASS RefCount
  24. //
  25. //****************************************************************************
  26. class RefCount
  27. {
  28. private:
  29. LONG m_cRef;
  30. public:
  31. RefCount();
  32. // Virtual destructor defers destruction to destructor of derived class.
  33. virtual ~RefCount();
  34. ULONG STDMETHODCALLTYPE AddRef(void);
  35. ULONG STDMETHODCALLTYPE Release(void);
  36. };
  37. //****************************************************************************
  38. //
  39. // CLASS CNotify
  40. //
  41. // Notification sink
  42. //
  43. //****************************************************************************
  44. class CNotify
  45. {
  46. private:
  47. DWORD m_dwCookie;
  48. IUnknown * m_pUnk;
  49. IConnectionPoint * m_pcnp;
  50. IConnectionPointContainer * m_pcnpcnt;
  51. public:
  52. CNotify(void);
  53. ~CNotify();
  54. HRESULT Connect(IUnknown *pUnk, REFIID riid, IUnknown *pUnkN);
  55. HRESULT Disconnect(void);
  56. IUnknown * GetPunk() {return m_pUnk;}
  57. };
  58. //****************************************************************************
  59. //
  60. // CLASS BSTRING
  61. //
  62. //****************************************************************************
  63. class BSTRING
  64. {
  65. private:
  66. BSTR m_bstr;
  67. public:
  68. // Constructors
  69. BSTRING() {m_bstr = NULL;}
  70. inline BSTRING(LPCWSTR lpcwString);
  71. #ifndef UNICODE
  72. // We don't support construction from an ANSI string in the Unicode build.
  73. BSTRING(LPCSTR lpcString);
  74. #endif // #ifndef UNICODE
  75. // Destructor
  76. inline ~BSTRING();
  77. // Cast to BSTR
  78. operator BSTR() {return m_bstr;}
  79. inline LPBSTR GetLPBSTR(void);
  80. };
  81. BSTRING::BSTRING(LPCWSTR lpcwString)
  82. {
  83. if (NULL != lpcwString)
  84. {
  85. m_bstr = SysAllocString(lpcwString);
  86. // ASSERT(NULL != m_bstr);
  87. }
  88. else
  89. {
  90. m_bstr = NULL;
  91. }
  92. }
  93. BSTRING::~BSTRING()
  94. {
  95. if (NULL != m_bstr)
  96. {
  97. SysFreeString(m_bstr);
  98. }
  99. }
  100. inline LPBSTR BSTRING::GetLPBSTR(void)
  101. {
  102. // This function is intended to be used to set the BSTR value for
  103. // objects that are initialized to NULL. It should not be called
  104. // on objects which already have a non-NULL BSTR.
  105. // ASSERT(NULL == m_bstr);
  106. return &m_bstr;
  107. }
  108. //****************************************************************************
  109. //
  110. // CLASS BTSTR
  111. //
  112. //****************************************************************************
  113. class BTSTR
  114. {
  115. private:
  116. LPTSTR m_psz;
  117. public:
  118. BTSTR(BSTR bstr);
  119. ~BTSTR();
  120. // Cast to BSTR
  121. operator LPTSTR() {return (NULL == m_psz) ? TEXT("<null>") : m_psz;}
  122. };
  123. LPTSTR LPTSTRfromBstr(BSTR bstr);
  124. #endif // _CL_UTIL_H_