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.

156 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. //****************************************************************************
  20. //
  21. // CLASS RefCount
  22. //
  23. //****************************************************************************
  24. class RefCount
  25. {
  26. private:
  27. LONG m_cRef;
  28. public:
  29. RefCount();
  30. // Virtual destructor defers destruction to destructor of derived class.
  31. virtual ~RefCount();
  32. ULONG STDMETHODCALLTYPE AddRef(void);
  33. ULONG STDMETHODCALLTYPE Release(void);
  34. };
  35. //****************************************************************************
  36. //
  37. // CLASS CNotify
  38. //
  39. // Notification sink
  40. //
  41. //****************************************************************************
  42. class CNotify
  43. {
  44. private:
  45. DWORD m_dwCookie;
  46. IUnknown * m_pUnk;
  47. IConnectionPoint * m_pcnp;
  48. IConnectionPointContainer * m_pcnpcnt;
  49. public:
  50. CNotify(void);
  51. ~CNotify();
  52. HRESULT Connect(IUnknown *pUnk, REFIID riid, IUnknown *pUnkN);
  53. HRESULT Disconnect(void);
  54. IUnknown * GetPunk() {return m_pUnk;}
  55. };
  56. //****************************************************************************
  57. //
  58. // CLASS BSTRING
  59. //
  60. //****************************************************************************
  61. class BSTRING
  62. {
  63. private:
  64. BSTR m_bstr;
  65. public:
  66. // Constructors
  67. BSTRING() {m_bstr = NULL;}
  68. inline BSTRING(LPCWSTR lpcwString);
  69. #ifndef UNICODE
  70. // We don't support construction from an ANSI string in the Unicode build.
  71. BSTRING(LPCSTR lpcString);
  72. #endif // #ifndef UNICODE
  73. // Destructor
  74. inline ~BSTRING();
  75. // Cast to BSTR
  76. operator BSTR() {return m_bstr;}
  77. inline LPBSTR GetLPBSTR(void);
  78. };
  79. BSTRING::BSTRING(LPCWSTR lpcwString)
  80. {
  81. if (NULL != lpcwString)
  82. {
  83. m_bstr = SysAllocString(lpcwString);
  84. // ASSERT(NULL != m_bstr);
  85. }
  86. else
  87. {
  88. m_bstr = NULL;
  89. }
  90. }
  91. BSTRING::~BSTRING()
  92. {
  93. if (NULL != m_bstr)
  94. {
  95. SysFreeString(m_bstr);
  96. }
  97. }
  98. inline LPBSTR BSTRING::GetLPBSTR(void)
  99. {
  100. // This function is intended to be used to set the BSTR value for
  101. // objects that are initialized to NULL. It should not be called
  102. // on objects which already have a non-NULL BSTR.
  103. // ASSERT(NULL == m_bstr);
  104. return &m_bstr;
  105. }
  106. //****************************************************************************
  107. //
  108. // CLASS BTSTR
  109. //
  110. //****************************************************************************
  111. class BTSTR
  112. {
  113. private:
  114. LPTSTR m_psz;
  115. public:
  116. BTSTR(BSTR bstr);
  117. ~BTSTR();
  118. // Cast to BSTR
  119. operator LPTSTR() {return (NULL == m_psz) ? TEXT("<null>") : m_psz;}
  120. };
  121. LPTSTR LPTSTRfromBstr(BSTR bstr);
  122. #endif // _CL_UTIL_H_