forked from Bush2021/chrome_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcom_initializer.h
More file actions
30 lines (25 loc) · 828 Bytes
/
Copy pathcom_initializer.h
File metadata and controls
30 lines (25 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef CHROME_PLUS_SRC_COM_INITIALIZER_H_
#define CHROME_PLUS_SRC_COM_INITIALIZER_H_
#include <objbase.h>
class ComInitializer {
public:
ComInitializer() {
const HRESULT hr = CoInitialize(nullptr);
initialized_ = SUCCEEDED(hr) || hr == RPC_E_CHANGED_MODE;
should_uninitialize_ = (hr == S_OK || hr == S_FALSE);
}
~ComInitializer() {
if (should_uninitialize_) {
CoUninitialize();
}
}
ComInitializer(const ComInitializer&) = delete;
ComInitializer& operator=(const ComInitializer&) = delete;
ComInitializer(ComInitializer&&) = delete;
ComInitializer& operator=(ComInitializer&&) = delete;
[[nodiscard]] bool IsInitialized() const { return initialized_; }
private:
bool initialized_ = false;
bool should_uninitialize_ = false;
};
#endif // CHROME_PLUS_SRC_COM_INITIALIZER_H_