ScopedFindFileHandle

class ScopedFindFileHandle {

 public:

  explicit ScopedFindFileHandle(HANDLE handle) : handle_(handle) {

    // Windows is inconsistent about invalid handles, so we always use NULL

    if (handle_ == INVALID_HANDLE_VALUE)

      handle_ = NULL;

  }

 

  ~ScopedFindFileHandle() {

    if (handle_)

      FindClose(handle_);

  }

 

  // Use this instead of comparing to INVALID_HANDLE_VALUE to pick up our NULL

  // usage for errors.

  bool IsValid() const { return handle_ != NULL; }

 

  operator HANDLE() { return handle_; }

 

 private:

  HANDLE handle_;

 

  DISALLOW_EVIL_CONSTRUCTORS(ScopedFindFileHandle);

};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章