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.

79 lines
2.0 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: refstr.h
  5. //
  6. // Description: Definition/Implementation of refcounted string. Used to hold
  7. // dynamic config data.
  8. //
  9. // Author: Mike Swafford (MikeSwa)
  10. //
  11. // History:
  12. // 10/8/98 - MikeSwa Created
  13. //
  14. // Copyright (C) 1998 Microsoft Corporation
  15. //
  16. //-----------------------------------------------------------------------------
  17. #ifndef __REFSTR_H__
  18. #define __REFSTR_H__
  19. #define CREFSTR_SIG_VALID 'rtSR'
  20. #define CREFSTR_SIG_INVALID 'rtS!'
  21. //---[ CRefCountedString ]-----------------------------------------------------
  22. //
  23. //
  24. // Description:
  25. // Implemenation of a ref-counted string. Designed to hold config data,
  26. // so that it can be passed to event sinks without holding a share lock.
  27. // Hungarian:
  28. // rstr, prstr
  29. //
  30. //-----------------------------------------------------------------------------
  31. class CRefCountedString : public CBaseObject
  32. {
  33. protected:
  34. DWORD m_dwSignature;
  35. DWORD m_cbStrlen; //length of string w/o NULL
  36. LPSTR m_szStr; //string data
  37. public:
  38. CRefCountedString()
  39. {
  40. m_dwSignature = CREFSTR_SIG_VALID;
  41. m_cbStrlen = 0;
  42. m_szStr = NULL;
  43. };
  44. ~CRefCountedString()
  45. {
  46. if (m_szStr)
  47. FreePv(m_szStr);
  48. m_szStr = NULL;
  49. m_cbStrlen = 0;
  50. m_dwSignature = CREFSTR_SIG_INVALID;
  51. }
  52. //Used to allocate memory for string
  53. // return FALSE if allocation fails
  54. BOOL fInit(LPSTR szStr, DWORD cbStrlen);
  55. //Return strlen of string
  56. DWORD cbStrlen()
  57. {
  58. _ASSERT(CREFSTR_SIG_VALID == m_dwSignature);
  59. return m_cbStrlen;
  60. };
  61. //Returns string
  62. LPSTR szStr()
  63. {
  64. _ASSERT(CREFSTR_SIG_VALID == m_dwSignature);
  65. return m_szStr;
  66. };
  67. };
  68. HRESULT HrUpdateRefCountedString(CRefCountedString **pprstrCurrent, LPSTR szNewString);
  69. #endif //__REFSTR_H__