ReactOS 0.4.15-dev-7924-g5949c20
comdef.h
Go to the documentation of this file.
1
6#ifndef _INC_COMDEF
7#define _INC_COMDEF
8
9#include <_mingw.h>
10
11#ifndef RC_INVOKED
12
13#ifndef __cplusplus
14#error Native Compiler support only available in C++ compiler
15#endif
16
17#include <ole2.h>
18#include <olectl.h>
19#include <comutil.h>
20
21#ifndef WINAPI
22#define WINAPI __stdcall
23#endif
24
25#ifdef __cplusplus
26
27class _com_error;
28void WINAPI _com_raise_error(HRESULT hr,IErrorInfo *perrinfo = 0);
29void WINAPI _set_com_error_handler(void (WINAPI *pHandler)(HRESULT hr,IErrorInfo *perrinfo));
32HRESULT WINAPI _com_dispatch_propget(IDispatch*,DISPID,VARTYPE,void*);
33HRESULT __cdecl _com_dispatch_propput(IDispatch*,DISPID,VARTYPE,...);
34HRESULT __cdecl _com_dispatch_method(IDispatch*,DISPID,WORD,VARTYPE,void*,const wchar_t*,...);
35HRESULT WINAPI _com_dispatch_raw_propget(IDispatch*,DISPID,VARTYPE,void*) throw();
36HRESULT __cdecl _com_dispatch_raw_propput(IDispatch*,DISPID,VARTYPE,...) throw();
37HRESULT __cdecl _com_dispatch_raw_method(IDispatch*,DISPID,WORD,VARTYPE,void*,const wchar_t*,...) throw();
38
39class _com_error {
40public:
41 _com_error(HRESULT hr,IErrorInfo *perrinfo = NULL,bool fAddRef = false) throw();
42 _com_error(const _com_error &that) throw();
43 virtual ~_com_error() throw();
44 _com_error &operator=(const _com_error &that) throw();
45 HRESULT Error() const throw();
46 WORD WCode() const throw();
47 IErrorInfo *ErrorInfo() const throw();
48 _bstr_t Description() const;
49 DWORD HelpContext() const throw();
50 _bstr_t HelpFile() const;
51 _bstr_t Source() const;
52 GUID GUID_() const throw();
53 const TCHAR *ErrorMessage() const throw();
54 static HRESULT WCodeToHRESULT(WORD wCode) throw();
55 static WORD HRESULTToWCode(HRESULT hr) throw();
56private:
57 void Dtor() throw();
58 void Ctor(const _com_error &that) throw();
59 enum {
60 WCODE_HRESULT_FIRST = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,0x200),WCODE_HRESULT_LAST = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF+1,0) - 1
61 };
62 HRESULT m_hresult;
63 IErrorInfo *m_perrinfo;
64 mutable TCHAR *m_pszMsg;
65};
66
67inline _com_error::_com_error(HRESULT hr,IErrorInfo *perrinfo,bool fAddRef) throw() : m_hresult(hr),m_perrinfo(perrinfo),m_pszMsg(NULL) {
68 if(m_perrinfo!=NULL && fAddRef) m_perrinfo->AddRef();
69}
70
71inline _com_error::_com_error(const _com_error &that) throw() {
72 Ctor(that);
73}
74
75inline _com_error::~_com_error() throw() {
76 Dtor();
77}
78
79inline _com_error &_com_error::operator=(const _com_error &that) throw() {
80 if(this!=&that) {
81 Dtor();
82 Ctor(that);
83 }
84 return *this;
85}
86
87inline HRESULT _com_error::Error() const throw() { return m_hresult; }
88inline WORD _com_error::WCode() const throw() { return HRESULTToWCode(m_hresult); }
89
90inline IErrorInfo *_com_error::ErrorInfo() const throw() {
91 if(m_perrinfo!=NULL) m_perrinfo->AddRef();
92 return m_perrinfo;
93}
94
95inline _bstr_t _com_error::Description() const {
96 BSTR bstr = NULL;
97 if(m_perrinfo!=NULL) m_perrinfo->GetDescription(&bstr);
98 return _bstr_t(bstr,false);
99}
100
101inline DWORD _com_error::HelpContext() const throw() {
102 DWORD dwHelpContext = 0;
103 if(m_perrinfo!=NULL) m_perrinfo->GetHelpContext(&dwHelpContext);
104 return dwHelpContext;
105}
106
107inline _bstr_t _com_error::HelpFile() const {
108 BSTR bstr = NULL;
109 if(m_perrinfo!=NULL) m_perrinfo->GetHelpFile(&bstr);
110 return _bstr_t(bstr,false);
111}
112
113inline _bstr_t _com_error::Source() const {
114 BSTR bstr = NULL;
115 if(m_perrinfo!=NULL) m_perrinfo->GetSource(&bstr);
116 return _bstr_t(bstr,false);
117}
118
119inline _GUID _com_error::GUID_() const throw() {
120 _GUID guid;
121 memset (&guid, 0, sizeof (_GUID));
122 if(m_perrinfo!=NULL) m_perrinfo->GetGUID(&guid);
123 return guid;
124}
125
126inline const TCHAR *_com_error::ErrorMessage() const throw() {
127 if(!m_pszMsg) {
129 if(m_pszMsg!=NULL) {
130 int nLen = lstrlen(m_pszMsg);
131 if(nLen > 1 && m_pszMsg[nLen - 1]=='\n') {
132 m_pszMsg[nLen-1] = 0;
133 if(m_pszMsg[nLen - 2]=='\r') m_pszMsg[nLen-2] = 0;
134 }
135 } else {
136 m_pszMsg = (LPTSTR)LocalAlloc(0,32 *sizeof(TCHAR));
137 if(m_pszMsg!=NULL) {
138 WORD wCode = WCode();
139 if(wCode!=0) {
140 _COM_PRINTF_S_1(m_pszMsg,32,TEXT("IDispatch error #%d"),wCode);
141 } else {
142 _COM_PRINTF_S_1(m_pszMsg,32,TEXT("Unknown error 0x%0lX"),m_hresult);
143 }
144 }
145 }
146 }
147 return m_pszMsg;
148}
149
150inline HRESULT _com_error::WCodeToHRESULT(WORD wCode) throw() { return wCode >= 0xFE00 ? WCODE_HRESULT_LAST : WCODE_HRESULT_FIRST + wCode; }
151inline WORD _com_error::HRESULTToWCode(HRESULT hr) throw() { return (hr >= WCODE_HRESULT_FIRST && hr <= WCODE_HRESULT_LAST) ? WORD(hr - WCODE_HRESULT_FIRST) : 0; }
152
153inline void _com_error::Dtor() throw() {
154 if(m_perrinfo!=NULL) m_perrinfo->Release();
155 if(m_pszMsg!=NULL) LocalFree((HLOCAL)m_pszMsg);
156}
157
158inline void _com_error::Ctor(const _com_error &that) throw() {
159 m_hresult = that.m_hresult;
160 m_perrinfo = that.m_perrinfo;
161 m_pszMsg = NULL;
162 if(m_perrinfo!=NULL) m_perrinfo->AddRef();
163}
164
165typedef int __missing_type__;
166
167#if !defined(_COM_SMARTPTR)
168#if !defined(_INC_COMIP)
169#include <comip.h>
170#endif
171#define _COM_SMARTPTR _com_ptr_t
172#define _COM_SMARTPTR_LEVEL2 _com_IIID
173#endif
174#if defined(_COM_SMARTPTR)
175#if !defined(_COM_SMARTPTR_TYPEDEF)
176#if defined(_COM_SMARTPTR_LEVEL2)
177#define _COM_SMARTPTR_TYPEDEF(Interface,IID) UUID IIDArgForTypedef ## Interface = IID; typedef _COM_SMARTPTR< _COM_SMARTPTR_LEVEL2<Interface, &IIDArgForTypedef ## Interface > > Interface ## Ptr
178#else
179#define _COM_SMARTPTR_TYPEDEF(Interface,IID) UUID IIDArgForTypedef ## Interface = IID; typedef _COM_SMARTPTR<Interface,&IIDArgForTypedef ## Interface > Interface ## Ptr
180#endif
181#endif
182#endif
183
184#if !defined(_COM_NO_STANDARD_GUIDS_)
185#if defined(__IFontDisp_INTERFACE_DEFINED__)
186#if !defined(Font)
187 struct Font : IFontDisp {};
188#endif
189_COM_SMARTPTR_TYPEDEF(Font, IID_IDispatch);
190
191#endif
192#if defined(__IFontEventsDisp_INTERFACE_DEFINED__)
193#if !defined(FontEvents)
194 struct FontEvents : IFontEventsDisp {};
195#endif
196_COM_SMARTPTR_TYPEDEF(FontEvents, IID_IDispatch);
197#endif
198#if defined(__IPictureDisp_INTERFACE_DEFINED__)
199#if !defined(Picture)
200 struct Picture : IPictureDisp {};
201#endif
202_COM_SMARTPTR_TYPEDEF(Picture, IID_IDispatch);
203#endif
204
205#include "comdefsp.h"
206#endif
207#endif
208
209#endif /* __cplusplus */
210
211#endif
#define __cdecl
Definition: accygwin.h:79
static VOID ErrorMessage(_In_ DWORD dwErrorCode, _In_opt_ PCWSTR pszMsg,...)
Definition: attrib.c:33
const WCHAR * class
Definition: main.c:68
static VOID HelpContext(PCONTEXT_ENTRY pContext)
Definition: help.c:39
BOOL Error
Definition: chkdsk.c:66
#define WINAPI
Definition: comdef.h:22
void WINAPI _com_issue_errorex(HRESULT hr, IUnknown *punk, REFIID riid)
Definition: comsupp.cpp:37
void WINAPI _com_issue_error(HRESULT hr)
Definition: comsupp.cpp:32
void WINAPI _set_com_error_handler(COM_ERROR_HANDLER *phandler)
Definition: comsupp.cpp:27
void WINAPI _com_raise_error(HRESULT hr, IErrorInfo *perrinfo)
Definition: comsupp.cpp:22
#define _COM_PRINTF_S_1(dest, destsize, format, arg1)
Definition: comutil.h:19
#define NULL
Definition: types.h:112
static const WCHAR Description[]
Definition: oid.c:1266
OLECHAR * BSTR
Definition: compat.h:2293
unsigned short VARTYPE
Definition: compat.h:2254
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:30
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
ULONG AddRef()
#define TEXT(s)
Definition: k32.h:26
const GUID * guid
static VARIANTARG static DISPID
Definition: ordinal.c:52
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
const GUID IID_IDispatch
#define REFIID
Definition: guiddef.h:118
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
Definition: scsiwmi.h:51
operator
#define FormatMessage
Definition: winbase.h:3795
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
#define lstrlen
Definition: winbase.h:3876
#define FACILITY_ITF
Definition: winerror.h:26
#define SEVERITY_ERROR
Definition: winerror.h:65
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define const
Definition: zconf.h:233