mirror of https://github.com/tongzx/nt5src
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
595 B
37 lines
595 B
// Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
|
|
// SmartHandle.h
|
|
|
|
|
|
class SmartHandle
|
|
{
|
|
public:
|
|
SmartHandle() : m_h(NULL) {}
|
|
~SmartHandle()
|
|
{
|
|
if(m_h)
|
|
{
|
|
::CloseHandle(m_h);
|
|
}
|
|
}
|
|
|
|
SmartHandle& operator=(const HANDLE h)
|
|
{
|
|
if(m_h)
|
|
{
|
|
::CloseHandle(m_h); m_h = NULL;
|
|
}
|
|
m_h = h;
|
|
return *this;
|
|
}
|
|
|
|
operator bool() const
|
|
{
|
|
if(m_h) return true;
|
|
else return false;
|
|
}
|
|
|
|
operator HANDLE() const { return m_h; }
|
|
|
|
private:
|
|
HANDLE m_h;
|
|
};
|