13 #error comip.h header cannot be included under /clr:safe or /clr:pure
16 #if !defined(_INC_COMIP)
25 #pragma warning(disable: 4290)
27 #pragma push_macro("new")
35 struct __declspec(uuid("00000000-0000-0000-c000-000000000046")) IUnknown;
39 template<
typename _Interface,
const IID* _IID >
75 return ThisIIID::GetIID();
85 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
92 template<
typename _InterfaceType>
_com_ptr_t(_InterfaceType* p)
97 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
149 #if defined(_NATIVE_NULLPTR_SUPPORTED) && !defined(_DO_NOT_USE_NULLPTR_IN_COM_PTR_T)
154 #endif // defined(_NATIVE_NULLPTR_SUPPORTED) && !defined(_DO_NOT_USE_NULLPTR_IN_COM_PTR_T)
190 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
202 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
215 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
228 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
239 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
252 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
270 if (pOldInterface !=
NULL) {
271 pOldInterface->Release();
303 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
322 void Attach(Interface* pInterface)
throw()
331 void Attach(Interface* pInterface,
bool fAddRef)
throw()
337 if (pInterface ==
NULL) {
341 pInterface->AddRef();
357 operator Interface*()
const throw()
365 operator Interface&()
const
427 template<
typename _InterfaceType>
bool operator==(_InterfaceType* p)
const
468 template<
typename _InterfaceType>
bool operator!=(_InterfaceType* p)
const
482 template<
typename _OtherIID>
bool operator<(const _com_ptr_t<_OtherIID>& p)
const
489 template<
typename _InterfaceType>
bool operator<(_InterfaceType* p)
const
503 template<
typename _InterfaceType>
bool operator>(_InterfaceType* p)
const
510 template<
typename _OtherIID>
bool operator<=(const _com_ptr_t<_OtherIID>& p)
const
517 template<
typename _InterfaceType>
bool operator<=(_InterfaceType* p)
const
531 template<
typename _InterfaceType>
bool operator>=(_InterfaceType* p)
const
584 if (dwClsContext & (CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)) {
586 hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));
589 hr = OleRun(pIUnknown);
595 pIUnknown->Release();
599 hr = CoCreateInstance(rclsid, pOuter, dwClsContext,
GetIID(), reinterpret_cast<void**>(&
m_pInterface));
615 if (clsidString ==
NULL) {
622 if (clsidString[0] == L
'{') {
623 hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
626 hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
641 if (clsidStringA ==
NULL) {
645 int size = lstrlenA(clsidStringA) + 1;
646 int destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, size,
NULL, 0);
649 return HRESULT_FROM_WIN32(GetLastError());
653 clsidStringW =
static_cast<LPWSTR
>(
_malloca(destSize *
sizeof(WCHAR)));
655 if (clsidStringW ==
NULL) {
656 return E_OUTOFMEMORY;
659 if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, clsidStringW, destSize) == 0) {
660 _freea(clsidStringW);
661 return HRESULT_FROM_WIN32(GetLastError());
665 _freea(clsidStringW);
683 pIUnknown->Release();
699 if (clsidString ==
NULL) {
706 if (clsidString[0] ==
'{') {
707 hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
710 hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
725 if (clsidStringA ==
NULL) {
729 int size = lstrlenA(clsidStringA) + 1;
730 int destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, size,
NULL, 0);
734 clsidStringW =
static_cast<LPWSTR
>(_alloca(destSize *
sizeof(WCHAR)));
740 if (clsidStringW ==
NULL) {
741 return E_OUTOFMEMORY;
744 if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, size, clsidStringW, destSize) == 0) {
745 return HRESULT_FROM_WIN32(GetLastError());
754 template<
typename _InterfaceType> HRESULT
QueryInterface(
const IID& iid, _InterfaceType*& p)
throw ()
757 return m_pInterface->QueryInterface(iid, reinterpret_cast<void**>(&p));
766 template<
typename _InterfaceType> HRESULT
QueryInterface(
const IID& iid, _InterfaceType** p)
throw()
781 if (m_pInterface !=
NULL) {
782 m_pInterface->Release();
790 if (m_pInterface !=
NULL) {
791 m_pInterface->AddRef();
809 Interface* pInterface;
810 hr = p->QueryInterface(
GetIID(), reinterpret_cast<void**>(&pInterface));
829 IUnknown* pu1 =
NULL;
830 IUnknown* pu2 =
NULL;
832 if (m_pInterface !=
NULL) {
833 HRESULT hr = m_pInterface->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu1));
845 HRESULT hr = p->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu2));
861 return (pu1 > pu2) ? 1 : -1;
869 if (V_VT(&varSrc) == VT_DISPATCH) {
873 if (V_VT(&varSrc) == VT_UNKNOWN) {
882 VariantInit(&varDest);
884 HRESULT hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_DISPATCH);
889 if (hr == E_NOINTERFACE) {
892 VariantInit(&varDest);
893 hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_UNKNOWN);
899 VariantClear(&varDest);
934 template<
typename _Interface>
bool operator<(int null, const _com_ptr_t<_Interface>& p)
943 template<
typename _Interface,
typename _InterfacePtr>
bool operator<(_Interface* i, const _com_ptr_t<_InterfacePtr>& p)
962 template<
typename _Interface>
bool operator<=(int null, const _com_ptr_t<_Interface>& p)
971 template<
typename _Interface,
typename _InterfacePtr>
bool operator<=(_Interface* i, const _com_ptr_t<_InterfacePtr>& p)
990 #pragma pop_macro("new")
bool operator==(_InterfaceType *p) const
Definition: comip.h:427
void _AddRef()
Definition: comip.h:788
Interface & operator*() const
Definition: comip.h:377
bool operator>(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:496
bool operator!=(int null, const _com_ptr_t< _Interface > &p)
Definition: comip.h:920
bool operator==(int null, const _com_ptr_t< _InterfaceType > &p)
Definition: comip.h:906
_com_ptr_t(const _com_ptr_t &cp)
Definition: comip.h:158
HRESULT CreateInstance(LPCSTR clsidStringA, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:639
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:827
_com_ptr_t & operator=(const _variant_t &varSrc)
Definition: comip.h:299
Interface * operator->() const
Definition: comip.h:400
Interface *& GetInterfacePtr()
Definition: comip.h:570
bool operator>=(int null, const _com_ptr_t< _Interface > &p)
Definition: comip.h:976
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:800
static _Interface * GetInterfacePtr()
Definition: comip.h:44
void _Release()
Definition: comip.h:779
void __stdcall _com_issue_error(HRESULT)
_com_ptr_t(const _variant_t &varSrc)
Definition: comip.h:185
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:420
_com_ptr_t()
Definition: comip.h:133
_com_ptr_t(LPCSTR str, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:223
_com_ptr_t(LPCWSTR str, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:210
bool operator!=(int null) const
Definition: comip.h:475
Definition: comutil.h:1002
HRESULT QueryStdInterfaces(const _variant_t &varSrc)
Definition: comip.h:867
_com_ptr_t(Interface *pInterface)
Definition: comip.h:166
#define NULL
Definition: crtdbg.h:30
bool operator<=(_InterfaceType *p) const
Definition: comip.h:517
struct __declspec(uuid("00000000-0000-0000-c000-000000000046")) IUnknown
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:578
_com_ptr_t(_In_ LPSTR str)
Definition: comip.h:104
int i[4]
Definition: dvec.h:70
#define _malloca(size)
Definition: malloc.h:228
#define _In_
Definition: sal.h:314
Interface * GetInterfacePtr() const
Definition: comip.h:563
#define FAILED(hr)
Definition: comutil.h:71
bool operator>=(_InterfaceType *p) const
Definition: comip.h:531
#define bool
Definition: stdbool.h:10
_com_ptr_t & operator=(Interface *pInterface)
Definition: comip.h:261
~_com_ptr_t()
Definition: comip.h:314
bool operator==(const _com_ptr_t &p) const
Definition: comip.h:443
_com_ptr_t(Interface *pInterface, bool fAddRef)
Definition: comip.h:175
_com_ptr_t & operator=(int null)
Definition: comip.h:288
bool operator==(Interface *p) const
Definition: comip.h:434
Interface * Detach()
Definition: comip.h:348
_com_ptr_t(int null)
Definition: comip.h:141
bool operator!=(_InterfaceType *p) const
Definition: comip.h:468
HRESULT CreateInstance(LPCWSTR clsidString, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:613
unsigned long DWORD
Definition: concrt.h:57
_com_ptr_t(_In_ LPWSTR str)
Definition: comip.h:111
Interface ** operator&()
Definition: comip.h:390
_com_ptr_t(_InterfaceType *p)
Definition: comip.h:92
#define GetExceptionCode
Definition: excpt.h:89
void Attach(Interface *pInterface, bool fAddRef)
Definition: comip.h:331
void Release()
Definition: comip.h:538
bool operator>=(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:524
bool operator<(_InterfaceType *p) const
Definition: comip.h:489
_com_ptr_t & operator=(const _com_ptr_t &cp)
Definition: comip.h:280
static const IID & GetIID()
Definition: comip.h:54
void Attach(Interface *pInterface)
Definition: comip.h:322
HRESULT GetActiveObject(const CLSID &rclsid)
Definition: comip.h:672
HRESULT QueryInterface(const IID &iid, _InterfaceType *&p)
Definition: comip.h:754
_com_ptr_t & operator=(_InterfaceType *p)
Definition: comip.h:248
_com_ptr_t & operator=(const _com_ptr_t< _OtherIID > &p)
Definition: comip.h:235
HRESULT QueryInterface(const IID &iid, _InterfaceType **p)
Definition: comip.h:766
HRESULT GetActiveObject(LPCSTR clsidStringA)
Definition: comip.h:723
Interface * m_pInterface
Definition: comip.h:774
static _Interface & GetInterface()
Definition: comip.h:49
_IIID ThisIIID
Definition: comip.h:65
bool operator>(int null, const _com_ptr_t< _Interface > &p)
Definition: comip.h:948
bool operator==(int null) const
Definition: comip.h:450
bool operator>(_InterfaceType *p) const
Definition: comip.h:503
_com_ptr_t(const _com_ptr_t< _OtherIID > &p)
Definition: comip.h:80
_Interface Interface
Definition: comip.h:42
HRESULT GetActiveObject(LPCWSTR clsidString)
Definition: comip.h:697
_com_ptr_t(const CLSID &clsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:197
_com_ptr_t(_com_ptr_t *p)
Definition: comip.h:119
static const IID & GetIID()
Definition: comip.h:73
void AddRef()
Definition: comip.h:551
_IIID::Interface Interface
Definition: comip.h:66
bool operator!=(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:461