mirror of https://github.com/x64dbg/btparser
51 lines
835 B
C
51 lines
835 B
C
|
#ifndef _HANDLE_H
|
||
|
#define _HANDLE_H
|
||
|
|
||
|
#include <windows.h>
|
||
|
|
||
|
class Handle
|
||
|
{
|
||
|
public:
|
||
|
Handle(HANDLE h = nullptr)
|
||
|
{
|
||
|
mHandle = h;
|
||
|
}
|
||
|
|
||
|
~Handle()
|
||
|
{
|
||
|
Close();
|
||
|
}
|
||
|
|
||
|
void Close()
|
||
|
{
|
||
|
DWORD dwFlags = 0;
|
||
|
if(GetHandleInformation(mHandle, &dwFlags) && !(dwFlags & HANDLE_FLAG_PROTECT_FROM_CLOSE))
|
||
|
CloseHandle(mHandle);
|
||
|
mHandle = INVALID_HANDLE_VALUE;
|
||
|
}
|
||
|
|
||
|
const HANDLE & operator=(const HANDLE & h)
|
||
|
{
|
||
|
return mHandle = h;
|
||
|
}
|
||
|
|
||
|
operator HANDLE & ()
|
||
|
{
|
||
|
return mHandle;
|
||
|
}
|
||
|
|
||
|
bool operator!() const
|
||
|
{
|
||
|
return (!mHandle || mHandle == INVALID_HANDLE_VALUE);
|
||
|
}
|
||
|
|
||
|
operator bool() const
|
||
|
{
|
||
|
return !this;
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
HANDLE mHandle;
|
||
|
};
|
||
|
|
||
|
#endif //_HANDLE_H
|