12 #if !defined(_INC_COMDEF)
14 #if !defined(RC_INVOKED)
17 #error Native Compiler support only available in C++ compiler
21 #error comdef.h header cannot be included under /clr:safe or /clr:pure
25 #include <winapifamily.h>
26 #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
27 #define _COMDEF_NOT_WINAPI_FAMILY_DESKTOP_APP
29 #if defined WINAPI_FAMILY_PHONE_APP && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
30 #define _COMDEF_WINAPI_FAMILY_PHONE_APP
34 #ifndef _COMDEF_WINAPI_FAMILY_PHONE_APP
41 #pragma warning(disable: 4244)
42 #pragma warning(disable: 4290)
44 #ifdef _COMDEF_NOT_WINAPI_FAMILY_DESKTOP_APP
46 #include <roerrorapi.h>
55 static wchar_t* AllocateString(
const wchar_t* message)
57 wchar_t* value =
nullptr;
58 if (message !=
nullptr)
67 ::wmemcpy(value, message, length);
73 _com_error(HRESULT hr,
const wchar_t* message) : m_hr(hr), m_message(nullptr)
75 m_message = AllocateString(message);
81 m_message = AllocateString(other.m_message);
87 m_message = other.m_message;
88 other.m_message =
nullptr;
102 m_message = AllocateString(other.m_message);
113 m_message = other.m_message;
114 other.m_message =
nullptr;
119 HRESULT
Error()
const throw()
126 if (m_message ==
nullptr)
128 wchar_t buffer[4096];
129 if (::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
132 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
137 m_message = AllocateString(buffer);
144 mutable wchar_t* m_message;
147 inline void __declspec(noreturn) __stdcall _com_raise_error(HRESULT hr, const
wchar_t* message)
149 size_t length = (message ==
nullptr) ? 0 : ::
wcslen(message);
156 ::Windows::Foundation::Diagnostics::OriginateError(hr, static_cast<unsigned int>(length), message);
160 typedef void (__stdcall *__errorPfnType)(HRESULT hr,
const wchar_t* message);
163 __declspec(selectany) __errorPfnType __errorPfn = &_com_raise_error;
167 __errorPfn(hr, message);
172 __errorPfn(hr,
nullptr);
177 __errorPfn = pHandler;
184 #ifdef _NATIVE_WCHAR_T_DEFINED
186 # pragma comment(lib, "comsuppwd.lib")
188 # pragma comment(lib, "comsuppw.lib")
192 # pragma comment(lib, "comsuppd.lib")
194 # pragma comment(lib, "comsupp.lib")
198 #pragma comment(lib, "user32.lib")
199 #pragma comment(lib, "ole32.lib")
200 #pragma comment(lib, "oleaut32.lib")
205 _com_raise_error(HRESULT hr, IErrorInfo*
perrinfo = 0) ;
221 const
wchar_t*, ...) ;
229 const
wchar_t*, ...) throw();
236 IErrorInfo* perrinfo =
NULL,
237 bool fAddRef =
false)
throw();
246 _com_error&
operator=(
const _com_error& that)
throw();
250 HRESULT
Error()
const throw();
251 WORD
WCode()
const throw();
283 bool fAddRef)
throw()
349 DWORD dwHelpContext = 0;
355 return dwHelpContext;
395 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
396 FORMAT_MESSAGE_FROM_SYSTEM|
397 FORMAT_MESSAGE_IGNORE_INSERTS,
400 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
404 if (m_pszMsg !=
NULL) {
405 int nLen = lstrlen(m_pszMsg);
406 if (nLen > 1 && m_pszMsg[nLen - 1] ==
'\n') {
407 m_pszMsg[nLen - 1] = 0;
408 if (m_pszMsg[nLen - 2] ==
'\r') {
409 m_pszMsg[nLen - 2] = 0;
414 m_pszMsg = (LPTSTR)LocalAlloc(0, 32 *
sizeof(
TCHAR));
415 if (m_pszMsg !=
NULL) {
416 WORD wCode =
WCode();
418 _COM_PRINTF_S_1(m_pszMsg, 32, TEXT(
"IDispatch error #%d"), (
int)wCode);
446 #if !defined(_COM_SMARTPTR)
447 #if !defined(_INC_COMIP)
450 #define _COM_SMARTPTR _com_ptr_t
451 #define _COM_SMARTPTR_LEVEL2 _com_IIID
453 #if defined(_COM_SMARTPTR)
454 #if !defined(_COM_SMARTPTR_TYPEDEF)
455 #if defined(_COM_SMARTPTR_LEVEL2)
456 #define _COM_SMARTPTR_TYPEDEF(Interface, IID) \
457 typedef _COM_SMARTPTR<_COM_SMARTPTR_LEVEL2<Interface, &IID> > \
460 #define _COM_SMARTPTR_TYPEDEF(Interface, IID) \
461 typedef _COM_SMARTPTR<Interface, &IID> \
467 #if !defined(_COM_NO_STANDARD_GUIDS_)
470 #if defined(__IFontDisp_INTERFACE_DEFINED__)
471 __if_not_exists(Font)
473 struct Font : IFontDisp {};
477 #if defined(__IFontEventsDisp_INTERFACE_DEFINED__)
478 __if_not_exists(FontEvents)
480 struct FontEvents : IFontEventsDisp {};
484 #if defined(__IPictureDisp_INTERFACE_DEFINED__)
485 __if_not_exists(Picture)
487 struct Picture : IPictureDisp {};
Definition: comutil.h:144
void __stdcall _set_com_error_handler(void(__stdcall *pHandler)(HRESULT hr, IErrorInfo *perrinfo))
const HRESULT m_hresult
Definition: comdef.h:276
_Check_return_ _CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_bstr_t HelpFile() const
Definition: comdef.h:358
HRESULT __cdecl _com_dispatch_propput(IDispatch *, DISPID, VARTYPE,...)
char TCHAR
Definition: tchar.h:2138
TCHAR * m_pszMsg
Definition: comdef.h:278
typedef void(__cdecl *_se_translator_function)(unsigned int
void __stdcall _com_issue_errorex(HRESULT, IUnknown *, REFIID)
HRESULT __stdcall _com_dispatch_raw_propget(IDispatch *, DISPID, VARTYPE, void *)
#define NULL
Definition: crtdbg.h:30
#define _countof(_Array)
Definition: stdlib.h:359
#define _COM_PRINTF_S_1(dest, destsize, format, arg1)
Definition: comutil.h:49
#define UINT_MAX
Definition: limits.h:41
HRESULT __cdecl _com_dispatch_raw_propput(IDispatch *, DISPID, VARTYPE,...)
virtual ~_com_error()
Definition: comdef.h:299
void __stdcall _com_issue_error(HRESULT)
#define FAILED(hr)
Definition: comutil.h:71
_bstr_t Description() const
Definition: comdef.h:336
HRESULT __cdecl _com_dispatch_method(IDispatch *, DISPID, WORD, VARTYPE, void *, const wchar_t *,...)
IErrorInfo * ErrorInfo() const
Definition: comdef.h:328
WORD WCode() const
Definition: comdef.h:323
_com_error & operator=(const _com_error &that)
Definition: comdef.h:309
_bstr_t Source() const
Definition: comdef.h:369
unsigned long DWORD
Definition: concrt.h:57
HRESULT __cdecl _com_dispatch_raw_method(IDispatch *, DISPID, WORD, VARTYPE, void *, const wchar_t *,...)
static WORD HRESULTToWCode(HRESULT hr)
Definition: comdef.h:434
HRESULT __stdcall _com_dispatch_propget(IDispatch *, DISPID, VARTYPE, void *)
int __missing_type__
Definition: comdef.h:444
static HRESULT WCodeToHRESULT(WORD wCode)
Definition: comdef.h:429
#define _COM_MEMCPY_S(dest, destsize, src, count)
Definition: comutil.h:48
const TCHAR * ErrorMessage() const
Definition: comdef.h:392
void IErrorInfo * perrinfo
Definition: comdef.h:205
#define _COM_SMARTPTR_TYPEDEF(Interface, IID)
Definition: comdef.h:456
DWORD HelpContext() const
Definition: comdef.h:347
IErrorInfo * m_perrinfo
Definition: comdef.h:277
HRESULT Error() const
Definition: comdef.h:318
void __declspec(noreturn) __stdcall _com_raise_error(HRESULT hr
_com_error(HRESULT hr, IErrorInfo *perrinfo=NULL, bool fAddRef=false)
Definition: comdef.h:281
GUID GUID() const
Definition: comdef.h:380