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.

118 lines
2.4 KiB

  1. /**************************************************************\
  2. FILE: ftpglob.cpp
  3. DESCRIPTION:
  4. Refcounted HGLOBAL.
  5. \**************************************************************/
  6. #include "priv.h"
  7. #include "ftpglob.h"
  8. /****************************************************\
  9. Constructor
  10. \****************************************************/
  11. CFtpGlob::CFtpGlob() : m_cRef(1)
  12. {
  13. DllAddRef();
  14. // This needs to be allocated in Zero Inited Memory.
  15. // Assert that all Member Variables are inited to Zero.
  16. ASSERT(!m_hglob);
  17. LEAK_ADDREF(LEAK_CFtpGlob);
  18. }
  19. /****************************************************\
  20. Destructor
  21. \****************************************************/
  22. CFtpGlob::~CFtpGlob()
  23. {
  24. if (m_hglob)
  25. GlobalFree(m_hglob);
  26. DllRelease();
  27. LEAK_DELREF(LEAK_CFtpGlob);
  28. }
  29. //===========================
  30. // *** IUnknown Interface ***
  31. ULONG CFtpGlob::AddRef()
  32. {
  33. m_cRef++;
  34. return m_cRef;
  35. }
  36. ULONG CFtpGlob::Release()
  37. {
  38. ASSERT(m_cRef > 0);
  39. m_cRef--;
  40. if (m_cRef > 0)
  41. return m_cRef;
  42. delete this;
  43. return 0;
  44. }
  45. HRESULT CFtpGlob::QueryInterface(REFIID riid, void **ppvObj)
  46. {
  47. if (IsEqualIID(riid, IID_IUnknown))
  48. {
  49. *ppvObj = SAFECAST(this, IUnknown*);
  50. }
  51. else
  52. {
  53. TraceMsg(TF_FTPQI, "CFtpGlob::QueryInterface() failed.");
  54. *ppvObj = NULL;
  55. return E_NOINTERFACE;
  56. }
  57. AddRef();
  58. return S_OK;
  59. }
  60. /****************************************************\
  61. FUNCTION: CFtpGlob_Create
  62. DESCRIPTION:
  63. This function will create an instance of the
  64. CFtpGlob object.
  65. \****************************************************/
  66. IUnknown * CFtpGlob_Create(HGLOBAL hglob)
  67. {
  68. IUnknown * punk = NULL;
  69. CFtpGlob * pfg = new CFtpGlob();
  70. if (pfg)
  71. {
  72. pfg->m_hglob = hglob;
  73. pfg->QueryInterface(IID_IUnknown, (LPVOID *)&punk);
  74. pfg->Release();
  75. }
  76. return punk;
  77. }
  78. /****************************************************\
  79. FUNCTION: CFtpGlob_CreateStr
  80. DESCRIPTION:
  81. This function will create an instance of the
  82. CFtpGlob object.
  83. \****************************************************/
  84. CFtpGlob * CFtpGlob_CreateStr(LPCTSTR pszStr)
  85. {
  86. CFtpGlob * pfg = new CFtpGlob();
  87. if (EVAL(pfg))
  88. pfg->m_hglob = (HGLOBAL) pszStr;
  89. return pfg;
  90. }