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.

37 lines
632 B

  1. // Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  2. // SmartHandle.h
  3. class SmartHandle
  4. {
  5. public:
  6. SmartHandle() : m_h(NULL) {}
  7. ~SmartHandle()
  8. {
  9. if(m_h)
  10. {
  11. ::CloseHandle(m_h);
  12. }
  13. }
  14. SmartHandle& operator=(const HANDLE h)
  15. {
  16. if(m_h)
  17. {
  18. ::CloseHandle(m_h); m_h = NULL;
  19. }
  20. m_h = h;
  21. return *this;
  22. }
  23. operator bool() const
  24. {
  25. if(m_h) return true;
  26. else return false;
  27. }
  28. operator HANDLE() const { return m_h; }
  29. private:
  30. HANDLE m_h;
  31. };