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.

85 lines
2.2 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: dll.hxx
  7. //
  8. // Contents: Classes for maintaining reference counts required to
  9. // implement
  10. //
  11. // Classes: CDll
  12. // CDllRef
  13. //
  14. // History: 06-26-1997 MarkBl Heisted from the eventlog snapin.
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef __DLLREF_HXX_
  18. #define __DLLREF_HXX_
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Class: CDll
  22. //
  23. // Purpose: Maintains reference and lock counts.
  24. //
  25. // History: 08-14-96 DavidMun Created
  26. //
  27. // Notes: Everything in this class is static, so nowhere is there an
  28. // instantiation of this class.
  29. //
  30. //----------------------------------------------------------------------------
  31. class CDll
  32. {
  33. public:
  34. static ULONG AddRef() { return InterlockedIncrement((LONG*)&s_cObjs); }
  35. static ULONG Release() { return InterlockedDecrement((LONG*)&s_cObjs); }
  36. static void LockServer(BOOL fLock) {
  37. fLock ? InterlockedIncrement((LONG*)&s_cLocks)
  38. : InterlockedDecrement((LONG*)&s_cLocks);
  39. }
  40. static HRESULT CanUnloadNow(void) {
  41. if (0L == s_cObjs && 0L == s_cLocks)
  42. {
  43. Dbg(DEB_TRACE, "Can unload\n");
  44. return S_OK;
  45. }
  46. Dbg(DEB_TRACE,
  47. "Can NOT unload, %u objects, %u locks\n",
  48. s_cObjs,
  49. s_cLocks);
  50. return S_FALSE;
  51. }
  52. static ULONG s_cObjs;
  53. static ULONG s_cLocks;
  54. }; // class CDll
  55. //+---------------------------------------------------------------------------
  56. //
  57. // Class: CDllRef
  58. //
  59. // Purpose: Helper class to automatically maintain object count.
  60. //
  61. // History: 08-14-96 DavidMun Created
  62. //
  63. // Notes: All objects returned to the outside world should contain
  64. // a CDllRef member.
  65. //
  66. //----------------------------------------------------------------------------
  67. class CDllRef
  68. {
  69. public:
  70. CDllRef(void) { CDll::AddRef(); }
  71. ~CDllRef(void) { CDll::Release(); }
  72. }; // class CDllRef
  73. #endif // __DLLREF_HXX_