mirror of
https://github.com/reactos/reactos.git
synced 2025-07-31 09:11:42 +00:00
[CRT]
- Import C++ compiler support headers from mingw-w64 (with some fixes) - Implement the required parts of the comsupp library svn path=/trunk/; revision=58223
This commit is contained in:
parent
8479fd6f47
commit
9f6d7cdd67
7 changed files with 3170 additions and 0 deletions
211
reactos/include/crt/comdef.h
Normal file
211
reactos/include/crt/comdef.h
Normal file
|
@ -0,0 +1,211 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the mingw-w64 runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
#ifndef _INC_COMDEF
|
||||
#define _INC_COMDEF
|
||||
|
||||
#include <_mingw.h>
|
||||
|
||||
#ifndef RC_INVOKED
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error Native Compiler support only available in C++ compiler
|
||||
#endif
|
||||
|
||||
#include <ole2.h>
|
||||
#include <olectl.h>
|
||||
#include <comutil.h>
|
||||
|
||||
#ifndef WINAPI
|
||||
#define WINAPI __stdcall
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
class _com_error;
|
||||
void WINAPI _com_raise_error(HRESULT hr,IErrorInfo *perrinfo = 0);
|
||||
void WINAPI _set_com_error_handler(void (WINAPI *pHandler)(HRESULT hr,IErrorInfo *perrinfo));
|
||||
void WINAPI _com_issue_error(HRESULT);
|
||||
void WINAPI _com_issue_errorex(HRESULT,IUnknown*,REFIID);
|
||||
HRESULT WINAPI _com_dispatch_propget(IDispatch*,DISPID,VARTYPE,void*);
|
||||
HRESULT __cdecl _com_dispatch_propput(IDispatch*,DISPID,VARTYPE,...);
|
||||
HRESULT __cdecl _com_dispatch_method(IDispatch*,DISPID,WORD,VARTYPE,void*,const wchar_t*,...);
|
||||
HRESULT WINAPI _com_dispatch_raw_propget(IDispatch*,DISPID,VARTYPE,void*) throw();
|
||||
HRESULT __cdecl _com_dispatch_raw_propput(IDispatch*,DISPID,VARTYPE,...) throw();
|
||||
HRESULT __cdecl _com_dispatch_raw_method(IDispatch*,DISPID,WORD,VARTYPE,void*,const wchar_t*,...) throw();
|
||||
|
||||
class _com_error {
|
||||
public:
|
||||
_com_error(HRESULT hr,IErrorInfo *perrinfo = NULL,bool fAddRef = false) throw();
|
||||
_com_error(const _com_error &that) throw();
|
||||
virtual ~_com_error() throw();
|
||||
_com_error &operator=(const _com_error &that) throw();
|
||||
HRESULT Error() const throw();
|
||||
WORD WCode() const throw();
|
||||
IErrorInfo *ErrorInfo() const throw();
|
||||
_bstr_t Description() const;
|
||||
DWORD HelpContext() const throw();
|
||||
_bstr_t HelpFile() const;
|
||||
_bstr_t Source() const;
|
||||
GUID GUID_() const throw();
|
||||
const TCHAR *ErrorMessage() const throw();
|
||||
static HRESULT WCodeToHRESULT(WORD wCode) throw();
|
||||
static WORD HRESULTToWCode(HRESULT hr) throw();
|
||||
private:
|
||||
void Dtor() throw();
|
||||
void Ctor(const _com_error &that) throw();
|
||||
enum {
|
||||
WCODE_HRESULT_FIRST = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,0x200),WCODE_HRESULT_LAST = MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF+1,0) - 1
|
||||
};
|
||||
HRESULT m_hresult;
|
||||
IErrorInfo *m_perrinfo;
|
||||
mutable TCHAR *m_pszMsg;
|
||||
};
|
||||
|
||||
inline _com_error::_com_error(HRESULT hr,IErrorInfo *perrinfo,bool fAddRef) throw() : m_hresult(hr),m_perrinfo(perrinfo),m_pszMsg(NULL) {
|
||||
if(m_perrinfo!=NULL && fAddRef) m_perrinfo->AddRef();
|
||||
}
|
||||
|
||||
inline _com_error::_com_error(const _com_error &that) throw() {
|
||||
Ctor(that);
|
||||
}
|
||||
|
||||
inline _com_error::~_com_error() throw() {
|
||||
Dtor();
|
||||
}
|
||||
|
||||
inline _com_error &_com_error::operator=(const _com_error &that) throw() {
|
||||
if(this!=&that) {
|
||||
Dtor();
|
||||
Ctor(that);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline HRESULT _com_error::Error() const throw() { return m_hresult; }
|
||||
inline WORD _com_error::WCode() const throw() { return HRESULTToWCode(m_hresult); }
|
||||
|
||||
inline IErrorInfo *_com_error::ErrorInfo() const throw() {
|
||||
if(m_perrinfo!=NULL) m_perrinfo->AddRef();
|
||||
return m_perrinfo;
|
||||
}
|
||||
|
||||
inline _bstr_t _com_error::Description() const {
|
||||
BSTR bstr = NULL;
|
||||
if(m_perrinfo!=NULL) m_perrinfo->GetDescription(&bstr);
|
||||
return _bstr_t(bstr,false);
|
||||
}
|
||||
|
||||
inline DWORD _com_error::HelpContext() const throw() {
|
||||
DWORD dwHelpContext = 0;
|
||||
if(m_perrinfo!=NULL) m_perrinfo->GetHelpContext(&dwHelpContext);
|
||||
return dwHelpContext;
|
||||
}
|
||||
|
||||
inline _bstr_t _com_error::HelpFile() const {
|
||||
BSTR bstr = NULL;
|
||||
if(m_perrinfo!=NULL) m_perrinfo->GetHelpFile(&bstr);
|
||||
return _bstr_t(bstr,false);
|
||||
}
|
||||
|
||||
inline _bstr_t _com_error::Source() const {
|
||||
BSTR bstr = NULL;
|
||||
if(m_perrinfo!=NULL) m_perrinfo->GetSource(&bstr);
|
||||
return _bstr_t(bstr,false);
|
||||
}
|
||||
|
||||
inline _GUID _com_error::GUID_() const throw() {
|
||||
_GUID guid;
|
||||
memset (&guid, 0, sizeof (_GUID));
|
||||
if(m_perrinfo!=NULL) m_perrinfo->GetGUID(&guid);
|
||||
return guid;
|
||||
}
|
||||
|
||||
inline const TCHAR *_com_error::ErrorMessage() const throw() {
|
||||
if(!m_pszMsg) {
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,NULL,m_hresult,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&m_pszMsg,0,NULL);
|
||||
if(m_pszMsg!=NULL) {
|
||||
int nLen = lstrlen(m_pszMsg);
|
||||
if(nLen > 1 && m_pszMsg[nLen - 1]=='\n') {
|
||||
m_pszMsg[nLen-1] = 0;
|
||||
if(m_pszMsg[nLen - 2]=='\r') m_pszMsg[nLen-2] = 0;
|
||||
}
|
||||
} else {
|
||||
m_pszMsg = (LPTSTR)LocalAlloc(0,32 *sizeof(TCHAR));
|
||||
if(m_pszMsg!=NULL) {
|
||||
WORD wCode = WCode();
|
||||
if(wCode!=0) {
|
||||
_COM_PRINTF_S_1(m_pszMsg,32,TEXT("IDispatch error #%d"),wCode);
|
||||
} else {
|
||||
_COM_PRINTF_S_1(m_pszMsg,32,TEXT("Unknown error 0x%0lX"),m_hresult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_pszMsg;
|
||||
}
|
||||
|
||||
inline HRESULT _com_error::WCodeToHRESULT(WORD wCode) throw() { return wCode >= 0xFE00 ? WCODE_HRESULT_LAST : WCODE_HRESULT_FIRST + wCode; }
|
||||
inline WORD _com_error::HRESULTToWCode(HRESULT hr) throw() { return (hr >= WCODE_HRESULT_FIRST && hr <= WCODE_HRESULT_LAST) ? WORD(hr - WCODE_HRESULT_FIRST) : 0; }
|
||||
|
||||
inline void _com_error::Dtor() throw() {
|
||||
if(m_perrinfo!=NULL) m_perrinfo->Release();
|
||||
if(m_pszMsg!=NULL) LocalFree((HLOCAL)m_pszMsg);
|
||||
}
|
||||
|
||||
inline void _com_error::Ctor(const _com_error &that) throw() {
|
||||
m_hresult = that.m_hresult;
|
||||
m_perrinfo = that.m_perrinfo;
|
||||
m_pszMsg = NULL;
|
||||
if(m_perrinfo!=NULL) m_perrinfo->AddRef();
|
||||
}
|
||||
|
||||
typedef int __missing_type__;
|
||||
|
||||
#if !defined(_COM_SMARTPTR)
|
||||
#if !defined(_INC_COMIP)
|
||||
#include <comip.h>
|
||||
#endif
|
||||
#define _COM_SMARTPTR _com_ptr_t
|
||||
#define _COM_SMARTPTR_LEVEL2 _com_IIID
|
||||
#endif
|
||||
#if defined(_COM_SMARTPTR)
|
||||
#if !defined(_COM_SMARTPTR_TYPEDEF)
|
||||
#if defined(_COM_SMARTPTR_LEVEL2)
|
||||
#define _COM_SMARTPTR_TYPEDEF(Interface,IID) UUID IIDArgForTypedef ## Interface = IID; typedef _COM_SMARTPTR< _COM_SMARTPTR_LEVEL2<Interface, &IIDArgForTypedef ## Interface > > Interface ## Ptr
|
||||
#else
|
||||
#define _COM_SMARTPTR_TYPEDEF(Interface,IID) UUID IIDArgForTypedef ## Interface = IID; typedef _COM_SMARTPTR<Interface,&IIDArgForTypedef ## Interface > Interface ## Ptr
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(_COM_NO_STANDARD_GUIDS_)
|
||||
#if defined(__IFontDisp_INTERFACE_DEFINED__)
|
||||
#if !defined(Font)
|
||||
struct Font : IFontDisp {};
|
||||
#endif
|
||||
_COM_SMARTPTR_TYPEDEF(Font, IID_IDispatch);
|
||||
|
||||
#endif
|
||||
#if defined(__IFontEventsDisp_INTERFACE_DEFINED__)
|
||||
#if !defined(FontEvents)
|
||||
struct FontEvents : IFontEventsDisp {};
|
||||
#endif
|
||||
_COM_SMARTPTR_TYPEDEF(FontEvents, IID_IDispatch);
|
||||
#endif
|
||||
#if defined(__IPictureDisp_INTERFACE_DEFINED__)
|
||||
#if !defined(Picture)
|
||||
struct Picture : IPictureDisp {};
|
||||
#endif
|
||||
_COM_SMARTPTR_TYPEDEF(Picture, IID_IDispatch);
|
||||
#endif
|
||||
|
||||
#include "comdefsp.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
1316
reactos/include/crt/comdefsp.h
Normal file
1316
reactos/include/crt/comdefsp.h
Normal file
File diff suppressed because it is too large
Load diff
378
reactos/include/crt/comip.h
Normal file
378
reactos/include/crt/comip.h
Normal file
|
@ -0,0 +1,378 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the mingw-w64 runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
#ifndef _INC_COMIP
|
||||
#define _INC_COMIP
|
||||
|
||||
#include <_mingw.h>
|
||||
|
||||
#include <ole2.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <comutil.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#pragma push_macro("new")
|
||||
#undef new
|
||||
|
||||
#include <new.h>
|
||||
|
||||
class _com_error;
|
||||
|
||||
#ifndef WINAPI
|
||||
#define WINAPI __stdcall
|
||||
#endif
|
||||
|
||||
void WINAPI _com_issue_error(HRESULT);
|
||||
struct IUnknown;
|
||||
|
||||
template<typename _Interface,const IID *_IID >
|
||||
class _com_IIID {
|
||||
public:
|
||||
typedef _Interface Interface;
|
||||
static _Interface *GetInterfacePtr() throw() { return NULL; }
|
||||
static _Interface& GetInterface() throw() { return *GetInterfacePtr(); }
|
||||
static const IID& GetIID() throw() { return *_IID; }
|
||||
};
|
||||
|
||||
template<typename _IIID> class _com_ptr_t {
|
||||
public:
|
||||
typedef _IIID ThisIIID;
|
||||
typedef typename _IIID::Interface Interface;
|
||||
static const IID& GetIID() throw() { return ThisIIID::GetIID(); }
|
||||
template<typename _OtherIID> _com_ptr_t(const _com_ptr_t<_OtherIID> &p) : m_pInterface(NULL) {
|
||||
HRESULT hr = _QueryInterface(p);
|
||||
if(FAILED(hr) && (hr!=E_NOINTERFACE)) { _com_issue_error(hr); }
|
||||
}
|
||||
template<typename _InterfaceType> _com_ptr_t(_InterfaceType *p) : m_pInterface(NULL) {
|
||||
HRESULT hr = _QueryInterface(p);
|
||||
if(FAILED(hr) && (hr!=E_NOINTERFACE)) { _com_issue_error(hr); }
|
||||
}
|
||||
template<typename _X> _com_ptr_t(LPSTR str) { new(this) _com_ptr_t(static_cast<LPCSTR> (str),NULL); }
|
||||
template<typename _X> _com_ptr_t(LPWSTR str) { new(this) _com_ptr_t(static_cast<LPCWSTR> (str),NULL); }
|
||||
template<typename _X> explicit _com_ptr_t(_com_ptr_t *p) : m_pInterface(NULL) {
|
||||
if(!p) { _com_issue_error(E_POINTER); }
|
||||
else {
|
||||
m_pInterface = p->m_pInterface;
|
||||
AddRef();
|
||||
}
|
||||
}
|
||||
_com_ptr_t() throw() : m_pInterface(NULL) { }
|
||||
_com_ptr_t(int null) : m_pInterface(NULL) {
|
||||
if(null!=0) { _com_issue_error(E_POINTER); }
|
||||
}
|
||||
|
||||
#ifdef _NATIVE_NULLPTR_SUPPORTED
|
||||
_com_ptr_t(decltype(nullptr)) : m_pInterface(NULL) {}
|
||||
#endif
|
||||
|
||||
_com_ptr_t(const _com_ptr_t &cp) throw() : m_pInterface(cp.m_pInterface) { _AddRef(); }
|
||||
template<typename _X> _com_ptr_t(Interface *pInterface) throw() : m_pInterface(pInterface) { _AddRef(); }
|
||||
_com_ptr_t(Interface *pInterface,bool fAddRef) throw() : m_pInterface(pInterface) {
|
||||
if(fAddRef) _AddRef();
|
||||
}
|
||||
_com_ptr_t(const _variant_t& varSrc) : m_pInterface(NULL) {
|
||||
HRESULT hr = QueryStdInterfaces(varSrc);
|
||||
if(FAILED(hr) && (hr!=E_NOINTERFACE)) { _com_issue_error(hr); }
|
||||
}
|
||||
explicit _com_ptr_t(const CLSID &clsid,IUnknown *pOuter = NULL,DWORD dwClsContext = CLSCTX_ALL) : m_pInterface(NULL) {
|
||||
HRESULT hr = CreateInstance(clsid,pOuter,dwClsContext);
|
||||
if(FAILED(hr) && (hr!=E_NOINTERFACE)) { _com_issue_error(hr); }
|
||||
}
|
||||
explicit _com_ptr_t(LPCWSTR str,IUnknown *pOuter = NULL,DWORD dwClsContext = CLSCTX_ALL) : m_pInterface(NULL) {
|
||||
HRESULT hr = CreateInstance(str,pOuter,dwClsContext);
|
||||
if(FAILED(hr) && (hr!=E_NOINTERFACE)) { _com_issue_error(hr); }
|
||||
}
|
||||
explicit _com_ptr_t(LPCSTR str,IUnknown *pOuter = NULL,DWORD dwClsContext = CLSCTX_ALL) : m_pInterface(NULL) {
|
||||
HRESULT hr = CreateInstance(str,pOuter,dwClsContext);
|
||||
if(FAILED(hr) && (hr!=E_NOINTERFACE)) { _com_issue_error(hr); }
|
||||
}
|
||||
template<typename _OtherIID> _com_ptr_t &operator=(const _com_ptr_t<_OtherIID> &p) {
|
||||
HRESULT hr = _QueryInterface(p);
|
||||
if(FAILED(hr) && (hr!=E_NOINTERFACE)) { _com_issue_error(hr); }
|
||||
return *this;
|
||||
}
|
||||
template<typename _InterfaceType> _com_ptr_t &operator=(_InterfaceType *p) {
|
||||
HRESULT hr = _QueryInterface(p);
|
||||
if(FAILED(hr) && (hr!=E_NOINTERFACE)) { _com_issue_error(hr); }
|
||||
return *this;
|
||||
}
|
||||
template<typename _X> _com_ptr_t &operator=(Interface *pInterface) throw() {
|
||||
if(m_pInterface!=pInterface) {
|
||||
Interface *pOldInterface = m_pInterface;
|
||||
m_pInterface = pInterface;
|
||||
_AddRef();
|
||||
if(pOldInterface!=NULL) pOldInterface->Release();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
_com_ptr_t &operator=(const _com_ptr_t &cp) throw() { return operator=(cp.m_pInterface); }
|
||||
_com_ptr_t &operator=(int null) {
|
||||
if(null!=0) { _com_issue_error(E_POINTER); }
|
||||
return operator=(reinterpret_cast<Interface*>(NULL));
|
||||
}
|
||||
_com_ptr_t &operator=(const _variant_t& varSrc) {
|
||||
HRESULT hr = QueryStdInterfaces(varSrc);
|
||||
if(FAILED(hr) && (hr!=E_NOINTERFACE)) { _com_issue_error(hr); }
|
||||
return *this;
|
||||
}
|
||||
~_com_ptr_t() throw() { _Release(); }
|
||||
void Attach(Interface *pInterface) throw() {
|
||||
_Release();
|
||||
m_pInterface = pInterface;
|
||||
}
|
||||
void Attach(Interface *pInterface,bool fAddRef) throw() {
|
||||
_Release();
|
||||
m_pInterface = pInterface;
|
||||
if(fAddRef) {
|
||||
if(!pInterface) { _com_issue_error(E_POINTER); }
|
||||
else pInterface->AddRef();
|
||||
}
|
||||
}
|
||||
Interface *Detach() throw() {
|
||||
Interface *const old = m_pInterface;
|
||||
m_pInterface = NULL;
|
||||
return old;
|
||||
}
|
||||
operator Interface*() const throw() { return m_pInterface; }
|
||||
operator Interface&() const {
|
||||
if(!m_pInterface) { _com_issue_error(E_POINTER); }
|
||||
return *m_pInterface;
|
||||
}
|
||||
Interface& operator*() const {
|
||||
if(!m_pInterface) { _com_issue_error(E_POINTER); }
|
||||
return *m_pInterface;
|
||||
}
|
||||
Interface **operator&() throw() {
|
||||
_Release();
|
||||
m_pInterface = NULL;
|
||||
return &m_pInterface;
|
||||
}
|
||||
Interface *operator->() const {
|
||||
if(!m_pInterface) { _com_issue_error(E_POINTER); }
|
||||
return m_pInterface;
|
||||
}
|
||||
operator bool() const throw() { return m_pInterface!=NULL; }
|
||||
template<typename _OtherIID> bool operator==(const _com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)==0; }
|
||||
template<typename _OtherIID> bool operator==(_com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)==0; }
|
||||
template<typename _InterfaceType> bool operator==(_InterfaceType *p) { return _CompareUnknown(p)==0; }
|
||||
template<typename _X> bool operator==(Interface *p) { return (m_pInterface==p) ? true : _CompareUnknown(p)==0; }
|
||||
template<typename _X> bool operator==(const _com_ptr_t &p) throw() { return operator==(p.m_pInterface); }
|
||||
template<typename _X> bool operator==(_com_ptr_t &p) throw() { return operator==(p.m_pInterface); }
|
||||
bool operator==(int null) {
|
||||
if(null!=0) { _com_issue_error(E_POINTER); }
|
||||
return !m_pInterface;
|
||||
}
|
||||
template<typename _OtherIID> bool operator!=(const _com_ptr_t<_OtherIID> &p) { return !(operator==(p)); }
|
||||
template<typename _OtherIID> bool operator!=(_com_ptr_t<_OtherIID> &p) { return !(operator==(p)); }
|
||||
template<typename _InterfaceType> bool operator!=(_InterfaceType *p) { return !(operator==(p)); }
|
||||
bool operator!=(int null) { return !(operator==(null)); }
|
||||
template<typename _OtherIID> bool operator<(const _com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)<0; }
|
||||
template<typename _OtherIID> bool operator<(_com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)<0; }
|
||||
template<typename _InterfaceType> bool operator<(_InterfaceType *p) { return _CompareUnknown(p)<0; }
|
||||
template<typename _OtherIID> bool operator>(const _com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)>0; }
|
||||
template<typename _OtherIID> bool operator>(_com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)>0; }
|
||||
template<typename _InterfaceType> bool operator>(_InterfaceType *p) { return _CompareUnknown(p)>0; }
|
||||
template<typename _OtherIID> bool operator<=(const _com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)<=0; }
|
||||
template<typename _OtherIID> bool operator<=(_com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)<=0; }
|
||||
template<typename _InterfaceType> bool operator<=(_InterfaceType *p) { return _CompareUnknown(p)<=0; }
|
||||
template<typename _OtherIID> bool operator>=(const _com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)>=0; }
|
||||
template<typename _OtherIID> bool operator>=(_com_ptr_t<_OtherIID> &p) { return _CompareUnknown(p)>=0; }
|
||||
template<typename _InterfaceType> bool operator>=(_InterfaceType *p) { return _CompareUnknown(p)>=0; }
|
||||
void Release() {
|
||||
if(!m_pInterface) { _com_issue_error(E_POINTER); }
|
||||
else {
|
||||
m_pInterface->Release();
|
||||
m_pInterface = NULL;
|
||||
}
|
||||
}
|
||||
void AddRef() {
|
||||
if(!m_pInterface) { _com_issue_error(E_POINTER); }
|
||||
else m_pInterface->AddRef();
|
||||
}
|
||||
Interface *GetInterfacePtr() const throw() { return m_pInterface; }
|
||||
Interface*& GetInterfacePtr() throw() { return m_pInterface; }
|
||||
HRESULT CreateInstance(const CLSID &rclsid,IUnknown *pOuter = NULL,DWORD dwClsContext = CLSCTX_ALL) throw() {
|
||||
HRESULT hr;
|
||||
_Release();
|
||||
if(dwClsContext & (CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)) {
|
||||
IUnknown *pIUnknown;
|
||||
hr = CoCreateInstance(rclsid,pOuter,dwClsContext,IID_IUnknown,reinterpret_cast<void**>(&pIUnknown));
|
||||
if(SUCCEEDED(hr)) {
|
||||
hr = OleRun(pIUnknown);
|
||||
if(SUCCEEDED(hr)) hr = pIUnknown->QueryInterface(GetIID(),reinterpret_cast<void**>(&m_pInterface));
|
||||
pIUnknown->Release();
|
||||
}
|
||||
} else hr = CoCreateInstance(rclsid,pOuter,dwClsContext,GetIID(),reinterpret_cast<void**>(&m_pInterface));
|
||||
if(FAILED(hr)) m_pInterface = NULL;
|
||||
return hr;
|
||||
}
|
||||
HRESULT CreateInstance(LPCWSTR clsidString,IUnknown *pOuter = NULL,DWORD dwClsContext = CLSCTX_ALL) throw() {
|
||||
if(!clsidString) return E_INVALIDARG;
|
||||
CLSID clsid;
|
||||
HRESULT hr;
|
||||
if(clsidString[0]==L'{') hr = CLSIDFromString(const_cast<LPWSTR> (clsidString),&clsid);
|
||||
else hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString),&clsid);
|
||||
if(FAILED(hr)) return hr;
|
||||
return CreateInstance(clsid,pOuter,dwClsContext);
|
||||
}
|
||||
HRESULT CreateInstance(LPCSTR clsidStringA,IUnknown *pOuter = NULL,DWORD dwClsContext = CLSCTX_ALL) throw() {
|
||||
if(!clsidStringA) return E_INVALIDARG;
|
||||
int size = lstrlenA(clsidStringA) + 1;
|
||||
int destSize = MultiByteToWideChar(CP_ACP,0,clsidStringA,size,NULL,0);
|
||||
if(destSize==0) return HRESULT_FROM_WIN32(GetLastError());
|
||||
LPWSTR clsidStringW;
|
||||
clsidStringW = static_cast<LPWSTR>(_malloca(destSize*sizeof(WCHAR)));
|
||||
if(!clsidStringW) return E_OUTOFMEMORY;
|
||||
if(MultiByteToWideChar(CP_ACP,0,clsidStringA,size,clsidStringW,destSize)==0) {
|
||||
_freea(clsidStringW);
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
HRESULT hr=CreateInstance(clsidStringW,pOuter,dwClsContext);
|
||||
_freea(clsidStringW);
|
||||
return hr;
|
||||
}
|
||||
HRESULT GetActiveObject(const CLSID &rclsid) throw() {
|
||||
_Release();
|
||||
IUnknown *pIUnknown;
|
||||
HRESULT hr = ::GetActiveObject(rclsid,NULL,&pIUnknown);
|
||||
if(SUCCEEDED(hr)) {
|
||||
hr = pIUnknown->QueryInterface(GetIID(),reinterpret_cast<void**>(&m_pInterface));
|
||||
pIUnknown->Release();
|
||||
}
|
||||
if(FAILED(hr)) m_pInterface = NULL;
|
||||
return hr;
|
||||
}
|
||||
HRESULT GetActiveObject(LPCWSTR clsidString) throw() {
|
||||
if(!clsidString) return E_INVALIDARG;
|
||||
CLSID clsid;
|
||||
HRESULT hr;
|
||||
if(clsidString[0]=='{') hr = CLSIDFromString(const_cast<LPWSTR> (clsidString),&clsid);
|
||||
else hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString),&clsid);
|
||||
if(FAILED(hr)) return hr;
|
||||
return GetActiveObject(clsid);
|
||||
}
|
||||
HRESULT GetActiveObject(LPCSTR clsidStringA) throw() {
|
||||
if(!clsidStringA) return E_INVALIDARG;
|
||||
int size = lstrlenA(clsidStringA) + 1;
|
||||
int destSize = MultiByteToWideChar(CP_ACP,0,clsidStringA,size,NULL,0);
|
||||
LPWSTR clsidStringW;
|
||||
try {
|
||||
clsidStringW = static_cast<LPWSTR>(_alloca(destSize*sizeof(WCHAR)));
|
||||
} catch (...) {
|
||||
clsidStringW = NULL;
|
||||
}
|
||||
if(!clsidStringW) return E_OUTOFMEMORY;
|
||||
if(MultiByteToWideChar(CP_ACP,0,clsidStringA,size,clsidStringW,destSize)==0) return HRESULT_FROM_WIN32(GetLastError());
|
||||
return GetActiveObject(clsidStringW);
|
||||
}
|
||||
template<typename _InterfaceType> HRESULT QueryInterface(const IID& iid,_InterfaceType*& p) throw () {
|
||||
if(m_pInterface!=NULL) return m_pInterface->QueryInterface(iid,reinterpret_cast<void**>(&p));
|
||||
return E_POINTER;
|
||||
}
|
||||
template<typename _InterfaceType> HRESULT QueryInterface(const IID& iid,_InterfaceType **p) throw() { return QueryInterface(iid,*p); }
|
||||
private:
|
||||
Interface *m_pInterface;
|
||||
void _Release() throw() {
|
||||
if(m_pInterface!=NULL) m_pInterface->Release();
|
||||
}
|
||||
void _AddRef() throw() {
|
||||
if(m_pInterface!=NULL) m_pInterface->AddRef();
|
||||
}
|
||||
template<typename _InterfacePtr> HRESULT _QueryInterface(_InterfacePtr p) throw() {
|
||||
HRESULT hr;
|
||||
if(p!=NULL) {
|
||||
Interface *pInterface;
|
||||
hr = p->QueryInterface(GetIID(),reinterpret_cast<void**>(&pInterface));
|
||||
Attach(SUCCEEDED(hr)? pInterface: NULL);
|
||||
} else {
|
||||
operator=(static_cast<Interface*>(NULL));
|
||||
hr = E_NOINTERFACE;
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
template<typename _InterfacePtr> int _CompareUnknown(_InterfacePtr p) {
|
||||
IUnknown *pu1,*pu2;
|
||||
if(m_pInterface!=NULL) {
|
||||
HRESULT hr = m_pInterface->QueryInterface(IID_IUnknown,reinterpret_cast<void**>(&pu1));
|
||||
if(FAILED(hr)) {
|
||||
_com_issue_error(hr);
|
||||
pu1 = NULL;
|
||||
} else pu1->Release();
|
||||
} else pu1 = NULL;
|
||||
if(p!=NULL) {
|
||||
HRESULT hr = p->QueryInterface(IID_IUnknown,reinterpret_cast<void**>(&pu2));
|
||||
if(FAILED(hr)) {
|
||||
_com_issue_error(hr);
|
||||
pu2 = NULL;
|
||||
} else pu2->Release();
|
||||
} else pu2 = NULL;
|
||||
return pu1 - pu2;
|
||||
}
|
||||
HRESULT QueryStdInterfaces(const _variant_t& varSrc) throw() {
|
||||
if(V_VT(&varSrc)==VT_DISPATCH) return _QueryInterface(V_DISPATCH(&varSrc));
|
||||
if(V_VT(&varSrc)==VT_UNKNOWN) return _QueryInterface(V_UNKNOWN(&varSrc));
|
||||
VARIANT varDest;
|
||||
VariantInit(&varDest);
|
||||
HRESULT hr = VariantChangeType(&varDest,const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)),0,VT_DISPATCH);
|
||||
if(SUCCEEDED(hr)) hr = _QueryInterface(V_DISPATCH(&varSrc));
|
||||
if(hr==E_NOINTERFACE) {
|
||||
VariantInit(&varDest);
|
||||
hr = VariantChangeType(&varDest,const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)),0,VT_UNKNOWN);
|
||||
if(SUCCEEDED(hr)) hr = _QueryInterface(V_UNKNOWN(&varSrc));
|
||||
}
|
||||
VariantClear(&varDest);
|
||||
return hr;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename _InterfaceType> bool operator==(int null,_com_ptr_t<_InterfaceType> &p) {
|
||||
if(null!=0) { _com_issue_error(E_POINTER); }
|
||||
return !p;
|
||||
}
|
||||
|
||||
template<typename _Interface,typename _InterfacePtr> bool operator==(_Interface *i,_com_ptr_t<_InterfacePtr> &p) { return p==i; }
|
||||
|
||||
template<typename _Interface> bool operator!=(int null,_com_ptr_t<_Interface> &p) {
|
||||
if(null!=0) { _com_issue_error(E_POINTER); }
|
||||
return p!=NULL;
|
||||
}
|
||||
|
||||
template<typename _Interface,typename _InterfacePtr> bool operator!=(_Interface *i,_com_ptr_t<_InterfacePtr> &p) { return p!=i; }
|
||||
|
||||
template<typename _Interface> bool operator<(int null,_com_ptr_t<_Interface> &p) {
|
||||
if(null!=0) { _com_issue_error(E_POINTER); }
|
||||
return p>NULL;
|
||||
}
|
||||
|
||||
template<typename _Interface,typename _InterfacePtr> bool operator<(_Interface *i,_com_ptr_t<_InterfacePtr> &p) { return p>i; }
|
||||
|
||||
template<typename _Interface> bool operator>(int null,_com_ptr_t<_Interface> &p) {
|
||||
if(null!=0) { _com_issue_error(E_POINTER); }
|
||||
return p<NULL;
|
||||
}
|
||||
|
||||
template<typename _Interface,typename _InterfacePtr> bool operator>(_Interface *i,_com_ptr_t<_InterfacePtr> &p) { return p<i; }
|
||||
|
||||
template<typename _Interface> bool operator<=(int null,_com_ptr_t<_Interface> &p) {
|
||||
if(null!=0) { _com_issue_error(E_POINTER); }
|
||||
return p>=NULL;
|
||||
}
|
||||
|
||||
template<typename _Interface,typename _InterfacePtr> bool operator<=(_Interface *i,_com_ptr_t<_InterfacePtr> &p) { return p>=i; }
|
||||
|
||||
template<typename _Interface> bool operator>=(int null,_com_ptr_t<_Interface> &p) {
|
||||
if(null!=0) { _com_issue_error(E_POINTER); }
|
||||
return p<=NULL;
|
||||
}
|
||||
|
||||
template<typename _Interface,typename _InterfacePtr> bool operator>=(_Interface *i,_com_ptr_t<_InterfacePtr> &p) { return p<=i; }
|
||||
|
||||
#pragma pop_macro("new")
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _INC_COMIP */
|
1212
reactos/include/crt/comutil.h
Normal file
1212
reactos/include/crt/comutil.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,5 @@
|
|||
|
||||
add_subdirectory(comsupp)
|
||||
add_subdirectory(crt)
|
||||
add_subdirectory(delayimp)
|
||||
add_subdirectory(dxguid)
|
||||
|
|
5
reactos/lib/sdk/comsupp/CMakeLists.txt
Normal file
5
reactos/lib/sdk/comsupp/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
set_cpp()
|
||||
|
||||
add_library(comsupp comsupp.cpp)
|
||||
add_dependencies(comsupp psdk)
|
47
reactos/lib/sdk/comsupp/comsupp.cpp
Normal file
47
reactos/lib/sdk/comsupp/comsupp.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* PROJECT: ReactOS crt library
|
||||
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
||||
* PURPOSE: Compiler support for COM
|
||||
* PROGRAMMER: Thomas Faber
|
||||
*/
|
||||
|
||||
#include <comdef.h>
|
||||
#include <comutil.h>
|
||||
|
||||
/* comdef.h */
|
||||
typedef void WINAPI COM_ERROR_HANDLER(HRESULT, IErrorInfo *);
|
||||
static COM_ERROR_HANDLER *com_error_handler;
|
||||
|
||||
void WINAPI _com_raise_error(HRESULT hr, IErrorInfo *perrinfo)
|
||||
{
|
||||
throw _com_error(hr, perrinfo);
|
||||
}
|
||||
|
||||
void WINAPI _set_com_error_handler(COM_ERROR_HANDLER *phandler)
|
||||
{
|
||||
com_error_handler = phandler;
|
||||
}
|
||||
|
||||
void WINAPI _com_issue_error(HRESULT hr)
|
||||
{
|
||||
com_error_handler(hr, NULL);
|
||||
}
|
||||
|
||||
void WINAPI _com_issue_errorex(HRESULT hr, IUnknown *punk, REFIID riid)
|
||||
{
|
||||
void *pv;
|
||||
IErrorInfo *perrinfo = NULL;
|
||||
|
||||
if (SUCCEEDED(punk->QueryInterface(riid, &pv)))
|
||||
{
|
||||
ISupportErrorInfo *pserrinfo = static_cast<ISupportErrorInfo *>(pv);
|
||||
if (pserrinfo->InterfaceSupportsErrorInfo(riid) == S_OK)
|
||||
(void)GetErrorInfo(0, &perrinfo);
|
||||
pserrinfo->Release();
|
||||
}
|
||||
|
||||
com_error_handler(hr, perrinfo);
|
||||
}
|
||||
|
||||
/* comutil.h */
|
||||
_variant_t vtMissing(DISP_E_PARAMNOTFOUND, VT_ERROR);
|
Loading…
Add table
Add a link
Reference in a new issue