libobs/util: Add WinModule RAII wrapper

master
jpark37 2021-09-04 19:40:34 -07:00 committed by Jim
parent 1aae05bd70
commit 7864c8649a
1 changed files with 31 additions and 0 deletions

View File

@ -49,3 +49,34 @@ public:
return handle && handle != INVALID_HANDLE_VALUE;
}
};
class WinModule {
HMODULE handle = NULL;
inline void Clear()
{
if (handle)
FreeLibrary(handle);
}
public:
inline WinModule() {}
inline WinModule(HMODULE handle_) : handle(handle_) {}
inline ~WinModule() { Clear(); }
inline operator HMODULE() const { return handle; }
inline WinModule &operator=(HMODULE handle_)
{
if (handle_ != handle) {
Clear();
handle = handle_;
}
return *this;
}
inline HMODULE *operator&() { return &handle; }
inline bool Valid() const { return handle != NULL; }
};