2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
14 #error Native Compiler support only available in C++ compiler
22 #define WINAPI __stdcall
28 void WINAPI
_com_raise_error(HRESULT hr
,IErrorInfo
*perrinfo
= 0);
29 void WINAPI
_set_com_error_handler(void (WINAPI
*pHandler
)(HRESULT hr
,IErrorInfo
*perrinfo
));
30 void WINAPI
_com_issue_error(HRESULT
);
31 void WINAPI
_com_issue_errorex(HRESULT
,IUnknown
*,REFIID
);
32 HRESULT WINAPI
_com_dispatch_propget(IDispatch
*,DISPID
,VARTYPE
,void*);
33 HRESULT __cdecl
_com_dispatch_propput(IDispatch
*,DISPID
,VARTYPE
,...);
34 HRESULT __cdecl
_com_dispatch_method(IDispatch
*,DISPID
,WORD
,VARTYPE
,void*,const wchar_t*,...);
35 HRESULT WINAPI
_com_dispatch_raw_propget(IDispatch
*,DISPID
,VARTYPE
,void*) throw();
36 HRESULT __cdecl
_com_dispatch_raw_propput(IDispatch
*,DISPID
,VARTYPE
,...) throw();
37 HRESULT __cdecl
_com_dispatch_raw_method(IDispatch
*,DISPID
,WORD
,VARTYPE
,void*,const wchar_t*,...) throw();
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();
58 void Ctor(const _com_error
&that
) throw();
60 WCODE_HRESULT_FIRST
= MAKE_HRESULT(SEVERITY_ERROR
,FACILITY_ITF
,0x200),WCODE_HRESULT_LAST
= MAKE_HRESULT(SEVERITY_ERROR
,FACILITY_ITF
+1,0) - 1
63 IErrorInfo
*m_perrinfo
;
64 mutable TCHAR
*m_pszMsg
;
67 inline _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();
71 inline _com_error::_com_error(const _com_error
&that
) throw() {
75 inline _com_error::~_com_error() throw() {
79 inline _com_error
&_com_error::operator=(const _com_error
&that
) throw() {
87 inline HRESULT
_com_error::Error() const throw() { return m_hresult
; }
88 inline WORD
_com_error::WCode() const throw() { return HRESULTToWCode(m_hresult
); }
90 inline IErrorInfo
*_com_error::ErrorInfo() const throw() {
91 if(m_perrinfo
!=NULL
) m_perrinfo
->AddRef();
95 inline _bstr_t
_com_error::Description() const {
97 if(m_perrinfo
!=NULL
) m_perrinfo
->GetDescription(&bstr
);
98 return _bstr_t(bstr
,false);
101 inline DWORD
_com_error::HelpContext() const throw() {
102 DWORD dwHelpContext
= 0;
103 if(m_perrinfo
!=NULL
) m_perrinfo
->GetHelpContext(&dwHelpContext
);
104 return dwHelpContext
;
107 inline _bstr_t
_com_error::HelpFile() const {
109 if(m_perrinfo
!=NULL
) m_perrinfo
->GetHelpFile(&bstr
);
110 return _bstr_t(bstr
,false);
113 inline _bstr_t
_com_error::Source() const {
115 if(m_perrinfo
!=NULL
) m_perrinfo
->GetSource(&bstr
);
116 return _bstr_t(bstr
,false);
119 inline _GUID
_com_error::GUID_() const throw() {
121 memset (&guid
, 0, sizeof (_GUID
));
122 if(m_perrinfo
!=NULL
) m_perrinfo
->GetGUID(&guid
);
126 inline const TCHAR
*_com_error::ErrorMessage() const throw() {
128 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,NULL
,m_hresult
,MAKELANGID(LANG_NEUTRAL
,SUBLANG_DEFAULT
),(LPTSTR
)&m_pszMsg
,0,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;
136 m_pszMsg
= (LPTSTR
)LocalAlloc(0,32 *sizeof(TCHAR
));
138 WORD wCode
= WCode();
140 _COM_PRINTF_S_1(m_pszMsg
,32,TEXT("IDispatch error #%d"),wCode
);
142 _COM_PRINTF_S_1(m_pszMsg
,32,TEXT("Unknown error 0x%0lX"),m_hresult
);
150 inline HRESULT
_com_error::WCodeToHRESULT(WORD wCode
) throw() { return wCode
>= 0xFE00 ? WCODE_HRESULT_LAST
: WCODE_HRESULT_FIRST
+ wCode
; }
151 inline WORD
_com_error::HRESULTToWCode(HRESULT hr
) throw() { return (hr
>= WCODE_HRESULT_FIRST
&& hr
<= WCODE_HRESULT_LAST
) ? WORD(hr
- WCODE_HRESULT_FIRST
) : 0; }
153 inline void _com_error::Dtor() throw() {
154 if(m_perrinfo
!=NULL
) m_perrinfo
->Release();
155 if(m_pszMsg
!=NULL
) LocalFree((HLOCAL
)m_pszMsg
);
158 inline void _com_error::Ctor(const _com_error
&that
) throw() {
159 m_hresult
= that
.m_hresult
;
160 m_perrinfo
= that
.m_perrinfo
;
162 if(m_perrinfo
!=NULL
) m_perrinfo
->AddRef();
165 typedef int __missing_type__
;
167 #if !defined(_COM_SMARTPTR)
168 #if !defined(_INC_COMIP)
171 #define _COM_SMARTPTR _com_ptr_t
172 #define _COM_SMARTPTR_LEVEL2 _com_IIID
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
179 #define _COM_SMARTPTR_TYPEDEF(Interface,IID) UUID IIDArgForTypedef ## Interface = IID; typedef _COM_SMARTPTR<Interface,&IIDArgForTypedef ## Interface > Interface ## Ptr
184 #if !defined(_COM_NO_STANDARD_GUIDS_)
185 #if defined(__IFontDisp_INTERFACE_DEFINED__)
187 struct Font
: IFontDisp
{};
189 _COM_SMARTPTR_TYPEDEF(Font
, IID_IDispatch
);
192 #if defined(__IFontEventsDisp_INTERFACE_DEFINED__)
193 #if !defined(FontEvents)
194 struct FontEvents
: IFontEventsDisp
{};
196 _COM_SMARTPTR_TYPEDEF(FontEvents
, IID_IDispatch
);
198 #if defined(__IPictureDisp_INTERFACE_DEFINED__)
199 #if !defined(Picture)
200 struct Picture
: IPictureDisp
{};
202 _COM_SMARTPTR_TYPEDEF(Picture
, IID_IDispatch
);
205 #include "comdefsp.h"
209 #endif /* __cplusplus */