-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOMInline.h
41 lines (36 loc) · 1.08 KB
/
COMInline.h
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
31
32
33
34
35
36
37
38
39
40
41
/*
Copyright (c) 2015-2021 hkrn All rights reserved
This file is part of emapp component and it's licensed under Mozilla Public License. see LICENSE.md for more details.
*/
#pragma once
#include "emapp/Error.h"
#include "emapp/Forward.h"
#include "emapp/StringUtils.h"
namespace nanoem {
namespace win32 {
class COMInline : private NonCopyable {
public:
template <typename TCOMInterface>
static inline void
safeRelease(TCOMInterface *&value)
{
if (value) {
value->Release();
value = nullptr;
}
}
static inline void
wrapCall(HRESULT result, Error &error)
{
if (FAILED(result) && !error.hasReason()) {
wchar_t buffer[Error::kMaxReasonLength];
MutableString msg;
FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM, nullptr, result, LANG_USER_DEFAULT, buffer, ARRAYSIZE(buffer), 0);
StringUtils::getMultiBytesString(buffer, msg);
error = Error(msg.data(), result, Error::kDomainTypeOS);
}
}
};
} /* namespace win32 */
} /* namespace nanoem */