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)
 
   60             auto length = ::wcslen(message) + 1; 
 
   61             value = 
new (std::nothrow) 
wchar_t[length];
 
   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 
  185 #if defined(_GUARDED_CRT) 
  187 # pragma comment(lib, "comsuppwgd.lib") 
  189 # pragma comment(lib, "comsuppwg.lib") 
  193 # pragma comment(lib, "comsuppwd.lib") 
  195 # pragma comment(lib, "comsuppw.lib") 
  199 #if defined(_GUARDED_CRT) 
  201 # pragma comment(lib, "comsuppgd.lib") 
  203 # pragma comment(lib, "comsuppg.lib") 
  207 # pragma comment(lib, "comsuppd.lib") 
  209 # pragma comment(lib, "comsupp.lib") 
  214 #pragma comment(lib, "user32.lib") 
  215 #pragma comment(lib, "ole32.lib") 
  216 #pragma comment(lib, "oleaut32.lib") 
  221     _com_raise_error(HRESULT hr, IErrorInfo* 
perrinfo = 0) ;
 
  237                          const 
wchar_t*, ...) ;
 
  245                              const 
wchar_t*, ...) throw();
 
  252                IErrorInfo* perrinfo = 
NULL,
 
  253                bool fAddRef = 
false) 
throw();
 
  262     _com_error& 
operator=(
const _com_error& that) 
throw();
 
  266     HRESULT 
Error() 
const throw();
 
  267     WORD 
WCode() 
const throw();
 
  299                               bool fAddRef) 
throw()
 
  365     DWORD dwHelpContext = 0;
 
  371     return dwHelpContext;
 
  410         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
 
  411                           FORMAT_MESSAGE_FROM_SYSTEM|
 
  412                           FORMAT_MESSAGE_IGNORE_INSERTS,
 
  415                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
 
  419         if (m_pszMsg != 
NULL) {
 
  421             size_t const nLen = wcslen(m_pszMsg);
 
  423             size_t const nLen = strlen(m_pszMsg);
 
  425             if (nLen > 1 && m_pszMsg[nLen - 1] == 
'\n') {
 
  426                 m_pszMsg[nLen - 1] = 0;
 
  427                 if (m_pszMsg[nLen - 2] == 
'\r') {
 
  428                         m_pszMsg[nLen - 2] = 0;
 
  433             m_pszMsg = (LPTSTR)LocalAlloc(0, 32 * 
sizeof(TCHAR));
 
  434             if (m_pszMsg != 
NULL) {
 
  435                 WORD wCode = 
WCode();
 
  437                     _COM_PRINTF_S_1(m_pszMsg, 32, TEXT(
"IDispatch error #%d"), (
int)wCode);
 
  465 #if !defined(_COM_SMARTPTR) 
  466  #if !defined(_INC_COMIP) 
  469  #define _COM_SMARTPTR        _com_ptr_t 
  470  #define _COM_SMARTPTR_LEVEL2 _com_IIID 
  472 #if defined(_COM_SMARTPTR) 
  473  #if !defined(_COM_SMARTPTR_TYPEDEF) 
  474   #if defined(_COM_SMARTPTR_LEVEL2) 
  475    #define _COM_SMARTPTR_TYPEDEF(Interface, IID) \ 
  476     typedef _COM_SMARTPTR<_COM_SMARTPTR_LEVEL2<Interface, &IID> > \ 
  479    #define _COM_SMARTPTR_TYPEDEF(Interface, IID) \ 
  480     typedef _COM_SMARTPTR<Interface, &IID> \ 
  486 #if !defined(_COM_NO_STANDARD_GUIDS_) 
  489 #if defined(__IFontDisp_INTERFACE_DEFINED__) 
  490 __if_not_exists(Font)
 
  492     struct Font : IFontDisp {};
 
  496 #if defined(__IFontEventsDisp_INTERFACE_DEFINED__) 
  497 __if_not_exists(FontEvents)
 
  499     struct FontEvents : IFontEventsDisp {};
 
  503 #if defined(__IPictureDisp_INTERFACE_DEFINED__) 
  504 __if_not_exists(Picture)
 
  506     struct Picture : IPictureDisp {};
 
Definition: comutil.h:144
 
void __stdcall _set_com_error_handler(void(__stdcall *pHandler)(HRESULT hr, IErrorInfo *perrinfo))
 
#define NULL
Definition: vcruntime.h:236
 
const HRESULT m_hresult
Definition: comdef.h:292
 
_bstr_t HelpFile() const 
Definition: comdef.h:374
 
HRESULT __cdecl _com_dispatch_propput(IDispatch *, DISPID, VARTYPE,...)
 
TCHAR * m_pszMsg
Definition: comdef.h:294
 
void __stdcall _com_issue_errorex(HRESULT, IUnknown *, REFIID)
 
HRESULT __stdcall _com_dispatch_raw_propget(IDispatch *, DISPID, VARTYPE, void *)
 
#define _COM_PRINTF_S_1(dest, destsize, format, arg1)
Definition: comutil.h:49
 
#define UINT_MAX
Definition: limits.h:36
 
HRESULT __cdecl _com_dispatch_raw_propput(IDispatch *, DISPID, VARTYPE,...)
 
virtual ~_com_error()
Definition: comdef.h:315
 
void __stdcall _com_issue_error(HRESULT)
 
#define FAILED(hr)
Definition: comutil.h:71
 
_bstr_t Description() const 
Definition: comdef.h:352
 
HRESULT __cdecl _com_dispatch_method(IDispatch *, DISPID, WORD, VARTYPE, void *, const wchar_t *,...)
 
IErrorInfo * ErrorInfo() const 
Definition: comdef.h:344
 
WORD WCode() const 
Definition: comdef.h:339
 
_com_error & operator=(const _com_error &that)
Definition: comdef.h:325
 
_bstr_t Source() const 
Definition: comdef.h:385
 
unsigned long DWORD
Definition: concrt.h:63
 
HRESULT __cdecl _com_dispatch_raw_method(IDispatch *, DISPID, WORD, VARTYPE, void *, const wchar_t *,...)
 
static WORD HRESULTToWCode(HRESULT hr)
Definition: comdef.h:453
 
HRESULT __stdcall _com_dispatch_propget(IDispatch *, DISPID, VARTYPE, void *)
 
int __missing_type__
Definition: comdef.h:463
 
static HRESULT WCodeToHRESULT(WORD wCode)
Definition: comdef.h:448
 
const TCHAR * ErrorMessage() const 
Definition: comdef.h:407
 
void IErrorInfo * perrinfo
Definition: comdef.h:221
 
#define _COM_SMARTPTR_TYPEDEF(Interface, IID)
Definition: comdef.h:475
 
DWORD HelpContext() const 
Definition: comdef.h:363
 
_CRT_BEGIN_C_HEADER typedef void(__CRTDECL *unexpected_handler)()
 
IErrorInfo * m_perrinfo
Definition: comdef.h:293
 
HRESULT Error() const 
Definition: comdef.h:334
 
void __declspec(noreturn) __stdcall _com_raise_error(HRESULT hr
 
_com_error(HRESULT hr, IErrorInfo *perrinfo=NULL, bool fAddRef=false)
Definition: comdef.h:297
 
GUID GUID() const 
Definition: comdef.h:396