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.

93 lines
1.8 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: SIMBSTR.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/12/1998
  12. *
  13. * DESCRIPTION: Simple CBSTR class
  14. *
  15. *******************************************************************************/
  16. #ifndef _SIMBSTR_H_INCLUDED
  17. #define _SIMBSTR_H_INCLUDED
  18. #include <windows.h>
  19. #include "simstr.h"
  20. class CSimpleBStr
  21. {
  22. private:
  23. BSTR m_BStr;
  24. public:
  25. CSimpleBStr( void )
  26. : m_BStr(NULL)
  27. {
  28. }
  29. CSimpleBStr( LPCWSTR pwstrString )
  30. : m_BStr(NULL)
  31. {
  32. AllocString(pwstrString);
  33. }
  34. CSimpleBStr( const CSimpleString &str )
  35. : m_BStr(NULL)
  36. {
  37. AllocString(CSimpleStringConvert::WideString(str).String());
  38. }
  39. CSimpleBStr( const CSimpleBStr &other )
  40. : m_BStr(NULL)
  41. {
  42. AllocString(other.WideString().String());
  43. }
  44. void AllocString( LPCWSTR pwstrString )
  45. {
  46. FreeString();
  47. if (pwstrString)
  48. {
  49. m_BStr = SysAllocString(pwstrString);
  50. }
  51. }
  52. void FreeString(void)
  53. {
  54. if (m_BStr)
  55. {
  56. SysFreeString(m_BStr);
  57. m_BStr = NULL;
  58. }
  59. }
  60. virtual ~CSimpleBStr(void)
  61. {
  62. FreeString();
  63. }
  64. CSimpleBStr &operator=( const CSimpleBStr &other )
  65. {
  66. AllocString(other.WideString().String());
  67. return *this;
  68. }
  69. CSimpleBStr &operator=( LPCWSTR lpwstrString )
  70. {
  71. AllocString(lpwstrString);
  72. return *this;
  73. }
  74. BSTR BString(void) const
  75. {
  76. return m_BStr;
  77. }
  78. operator BSTR(void) const
  79. {
  80. return m_BStr;
  81. }
  82. CSimpleStringWide WideString(void) const
  83. {
  84. return CSimpleStringConvert::WideString(CSimpleStringWide(m_BStr));
  85. }
  86. };
  87. #endif