-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
613 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*! @file */ | ||
/* | ||
Copyright (C) 2018-2020 Sakura Editor Organization | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
1. The origin of this software must not be misrepresented; | ||
you must not claim that you wrote the original software. | ||
If you use this software in a product, an acknowledgment | ||
in the product documentation would be appreciated but is | ||
not required. | ||
2. Altered source versions must be plainly marked as such, | ||
and must not be misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source | ||
distribution. | ||
*/ | ||
#include "StdAfx.h" | ||
#include "basis/CErrorInfo.h" | ||
|
||
/*! | ||
* コンストラクタ | ||
*/ | ||
CErrorInfo::CErrorInfo( | ||
std::wstring_view source, //!< [in] ソース | ||
std::wstring_view description //!< [in] 説明 | ||
) | ||
: bstrSource_(source.data()) | ||
, bstrDescription_(description.data()) | ||
{ | ||
} | ||
|
||
/*! | ||
* GUIDを取得する | ||
*/ | ||
IFACEMETHODIMP CErrorInfo::GetGUID(GUID *pGUID) | ||
{ | ||
if (!pGUID) return E_POINTER; | ||
*pGUID = GUID_NULL; | ||
return S_OK; | ||
} | ||
|
||
/*! | ||
* ソース情報を取得する | ||
*/ | ||
IFACEMETHODIMP CErrorInfo::GetSource(BSTR *pBstrSource) | ||
{ | ||
if (!pBstrSource) return E_POINTER; | ||
*pBstrSource = bstrSource_.copy(); | ||
return S_OK; | ||
} | ||
|
||
/*! | ||
* 説明を取得する | ||
*/ | ||
IFACEMETHODIMP CErrorInfo::GetDescription(BSTR *pBstrDescription) | ||
{ | ||
if (!pBstrDescription) return E_POINTER; | ||
*pBstrDescription = bstrDescription_.copy(); | ||
return S_OK; | ||
} | ||
|
||
/*! | ||
* ヘルプファイルのパスを取得する | ||
*/ | ||
IFACEMETHODIMP CErrorInfo::GetHelpFile(BSTR *pBstrHelpFile) | ||
{ | ||
if (!pBstrHelpFile) return E_POINTER; | ||
_bstr_t bstrHelpFile_; | ||
*pBstrHelpFile = bstrHelpFile_.copy(); | ||
return S_OK; | ||
} | ||
|
||
/*! | ||
* ヘルプコンテキストを取得する | ||
*/ | ||
IFACEMETHODIMP CErrorInfo::GetHelpContext(DWORD *pdwHelpContext) | ||
{ | ||
if (!pdwHelpContext) return E_POINTER; | ||
constexpr DWORD dwHelpContext_ = 0; | ||
*pdwHelpContext = dwHelpContext_; | ||
return S_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*! @file */ | ||
/* | ||
Copyright (C) 2018-2020 Sakura Editor Organization | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
1. The origin of this software must not be misrepresented; | ||
you must not claim that you wrote the original software. | ||
If you use this software in a product, an acknowledgment | ||
in the product documentation would be appreciated but is | ||
not required. | ||
2. Altered source versions must be plainly marked as such, | ||
and must not be misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source | ||
distribution. | ||
*/ | ||
#pragma once | ||
|
||
#include <Windows.h> | ||
|
||
#include <comdef.h> | ||
#include <OAIdl.h> | ||
|
||
#include <string_view> | ||
|
||
#include "basis/TComImpl.hpp" | ||
|
||
/*! | ||
* @brief COMエラー情報クラス | ||
* | ||
* Windowsのエラー情報を提供するために使用するクラスです。 | ||
* _com_raise_error関数にエラー情報を渡すことにより、日本語メッセージを含む例外を投げることができます。 | ||
* | ||
* @see https://docs.microsoft.com/en-us/windows/win32/api/oaidl/nn-oaidl-ierrorinfo | ||
* @see https://docs.microsoft.com/en-us/cpp/cpp/com-raise-error | ||
*/ | ||
class CErrorInfo : public TComImpl<IErrorInfo> { | ||
_bstr_t bstrSource_; | ||
_bstr_t bstrDescription_; | ||
|
||
public: | ||
CErrorInfo( | ||
std::wstring_view source, //!< [in] ソース | ||
std::wstring_view description //!< [in] 説明 | ||
); | ||
|
||
IFACEMETHODIMP GetGUID(GUID *pGUID) override; | ||
IFACEMETHODIMP GetSource(BSTR *pBstrSource) override; | ||
IFACEMETHODIMP GetDescription(BSTR *pBstrDescription) override; | ||
IFACEMETHODIMP GetHelpFile(BSTR *pBstrHelpFile) override; | ||
IFACEMETHODIMP GetHelpContext(DWORD *pdwHelpContext) override; | ||
}; | ||
|
||
//! メッセージからエラー情報を生成する | ||
#define MakeMsgError(msg) new CErrorInfo(_CRT_WIDE(__FILE__) L"(" _CRT_WIDE(_CRT_STRINGIZE(__LINE__)) L")", (msg)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*! @file */ | ||
/* | ||
Copyright (C) 2018-2020 Sakura Editor Organization | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
1. The origin of this software must not be misrepresented; | ||
you must not claim that you wrote the original software. | ||
If you use this software in a product, an acknowledgment | ||
in the product documentation would be appreciated but is | ||
not required. | ||
2. Altered source versions must be plainly marked as such, | ||
and must not be misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source | ||
distribution. | ||
*/ | ||
#pragma once | ||
|
||
#include <Windows.h> | ||
|
||
#include <comdef.h> | ||
#include <comutil.h> | ||
#include <OAIdl.h> | ||
|
||
#include <memory> | ||
#include <type_traits> | ||
|
||
/*! | ||
* TComImpl - COMオブジェクトの実装クラステンプレート | ||
* 使用上の注意: | ||
* 1. 生成はnewで行い、deleteはしないでください。 | ||
* 自動変数で生成するとヒープエラーが出ます。 | ||
* 2. 生成したらAddRef()し、不要になったらRelease()してください。 | ||
*/ | ||
template<class TargetInterface, class DeleterType = std::default_delete<TargetInterface>, std::enable_if_t<std::is_base_of_v<IUnknown, TargetInterface>, std::nullptr_t> = nullptr> | ||
class TComImpl : public TargetInterface | ||
{ | ||
LONG nRefCount_ = 0; | ||
|
||
using Me = TComImpl<TargetInterface>; | ||
|
||
public: | ||
TComImpl() = default; | ||
TComImpl(const Me&) = delete; | ||
Me& operator = (const Me&) = delete; | ||
TComImpl(Me&&) = delete; | ||
Me& operator = (Me&&) = delete; | ||
|
||
IFACEMETHODIMP QueryInterface(REFIID iid, void ** ppvObject) override | ||
{ | ||
if (ppvObject == nullptr) { | ||
return E_POINTER; | ||
} | ||
|
||
if (IsEqualIID(iid, __uuidof(TargetInterface)) || | ||
IsEqualIID(iid, IID_IUnknown)) | ||
{ | ||
*ppvObject = this; | ||
AddRef(); | ||
return S_OK; | ||
} | ||
|
||
return E_NOINTERFACE; | ||
} | ||
|
||
IFACEMETHODIMP_(ULONG) AddRef() override | ||
{ | ||
return ::InterlockedIncrement(&nRefCount_); | ||
} | ||
|
||
IFACEMETHODIMP_(ULONG) Release() override | ||
{ | ||
const LONG nRefCount = ::InterlockedDecrement(&nRefCount_); | ||
|
||
if (nRefCount == 0) { | ||
const DeleterType deletor; | ||
deletor(this); | ||
} | ||
|
||
return nRefCount; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*! @file */ | ||
/* | ||
Copyright (C) 2018-2020 Sakura Editor Organization | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
1. The origin of this software must not be misrepresented; | ||
you must not claim that you wrote the original software. | ||
If you use this software in a product, an acknowledgment | ||
in the product documentation would be appreciated but is | ||
not required. | ||
2. Altered source versions must be plainly marked as such, | ||
and must not be misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source | ||
distribution. | ||
*/ | ||
#include "StdAfx.h" | ||
#include <comdef.h> | ||
#include <OAIdl.h> | ||
|
||
/*! | ||
MinGW向け_com_raise_error実装 | ||
*/ | ||
void _com_raise_error(HRESULT hr, IErrorInfo* pErrorInfo) | ||
{ | ||
throw _com_error(hr, pErrorInfo, true); | ||
} |
Oops, something went wrong.