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)
169 cp.m_pInterface =
nullptr;
198 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
210 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
223 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
236 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
247 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
260 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
278 if (pOldInterface !=
nullptr) {
279 pOldInterface->Release();
301 cp.m_pInterface =
nullptr;
303 if (pOldInterface !=
nullptr) {
304 pOldInterface->Release();
329 if (
FAILED(hr) && (hr != E_NOINTERFACE)) {
348 void Attach(Interface* pInterface)
throw()
357 void Attach(Interface* pInterface,
bool fAddRef)
throw()
363 if (pInterface ==
NULL) {
367 pInterface->AddRef();
383 operator Interface*()
const throw()
391 operator Interface&()
const
453 template<
typename _InterfaceType>
bool operator==(_InterfaceType* p)
const
494 template<
typename _InterfaceType>
bool operator!=(_InterfaceType* p)
const
508 template<
typename _OtherIID>
bool operator<(const _com_ptr_t<_OtherIID>& p)
const
515 template<
typename _InterfaceType>
bool operator<(_InterfaceType* p)
const
529 template<
typename _InterfaceType>
bool operator>(_InterfaceType* p)
const
536 template<
typename _OtherIID>
bool operator<=(const _com_ptr_t<_OtherIID>& p)
const
543 template<
typename _InterfaceType>
bool operator<=(_InterfaceType* p)
const
557 template<
typename _InterfaceType>
bool operator>=(_InterfaceType* p)
const
610 if (dwClsContext & (CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)) {
612 hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));
615 hr = OleRun(pIUnknown);
621 pIUnknown->Release();
625 hr = CoCreateInstance(rclsid, pOuter, dwClsContext,
GetIID(), reinterpret_cast<void**>(&
m_pInterface));
641 if (clsidString ==
NULL) {
648 if (clsidString[0] == L
'{') {
649 hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
652 hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
667 if (clsidStringA ==
NULL) {
671 size_t const size = strlen(clsidStringA) + 1;
677 int const destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, static_cast<int>(size),
NULL, 0);
680 return HRESULT_FROM_WIN32(GetLastError());
684 clsidStringW =
static_cast<LPWSTR
>(_malloca(destSize *
sizeof(WCHAR)));
686 if (clsidStringW ==
NULL) {
687 return E_OUTOFMEMORY;
690 if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, static_cast<int>(size), clsidStringW, destSize) == 0) {
691 _freea(clsidStringW);
692 return HRESULT_FROM_WIN32(GetLastError());
696 _freea(clsidStringW);
714 pIUnknown->Release();
730 if (clsidString ==
NULL) {
737 if (clsidString[0] ==
'{') {
738 hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
741 hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
756 if (clsidStringA ==
NULL) {
760 size_t const size = strlen(clsidStringA) + 1;
766 int const destSize = MultiByteToWideChar(CP_ACP, 0, clsidStringA, static_cast<int>(size),
NULL, 0);
770 clsidStringW =
static_cast<LPWSTR
>(_alloca(destSize *
sizeof(WCHAR)));
776 if (clsidStringW ==
NULL) {
777 return E_OUTOFMEMORY;
780 if (MultiByteToWideChar(CP_ACP, 0, clsidStringA, static_cast<int>(size), clsidStringW, destSize) == 0) {
781 return HRESULT_FROM_WIN32(GetLastError());
790 template<
typename _InterfaceType> HRESULT
QueryInterface(
const IID& iid, _InterfaceType*& p)
throw ()
793 return m_pInterface->QueryInterface(iid, reinterpret_cast<void**>(&p));
802 template<
typename _InterfaceType> HRESULT
QueryInterface(
const IID& iid, _InterfaceType** p)
throw()
817 if (m_pInterface !=
NULL) {
818 m_pInterface->Release();
826 if (m_pInterface !=
NULL) {
827 m_pInterface->AddRef();
845 Interface* pInterface =
NULL;
846 hr = p->QueryInterface(
GetIID(), reinterpret_cast<void**>(&pInterface));
865 IUnknown* pu1 =
NULL;
866 IUnknown* pu2 =
NULL;
868 if (m_pInterface !=
NULL) {
869 HRESULT hr = m_pInterface->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu1));
881 HRESULT hr = p->QueryInterface(__uuidof(IUnknown), reinterpret_cast<void**>(&pu2));
897 return (pu1 > pu2) ? 1 : -1;
905 if (V_VT(&varSrc) == VT_DISPATCH) {
909 if (V_VT(&varSrc) == VT_UNKNOWN) {
918 VariantInit(&varDest);
920 HRESULT hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_DISPATCH);
925 if (hr == E_NOINTERFACE) {
928 VariantInit(&varDest);
929 hr = VariantChangeType(&varDest, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)), 0, VT_UNKNOWN);
935 VariantClear(&varDest);
970 template<
typename _Interface>
bool operator<(int null, const _com_ptr_t<_Interface>& p)
979 template<
typename _Interface,
typename _InterfacePtr>
bool operator<(_Interface* i, const _com_ptr_t<_InterfacePtr>& p)
998 template<
typename _Interface>
bool operator<=(int null, const _com_ptr_t<_Interface>& p)
1007 template<
typename _Interface,
typename _InterfacePtr>
bool operator<=(_Interface* i, const _com_ptr_t<_InterfacePtr>& p)
1026 #pragma pop_macro("new")
1027 #pragma warning(pop)
1029 #endif // _INC_COMIP
bool operator==(_InterfaceType *p) const
Definition: comip.h:453
void _AddRef()
Definition: comip.h:824
Interface & operator*() const
Definition: comip.h:403
#define NULL
Definition: vcruntime.h:236
bool operator>(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:522
bool operator!=(int null, const _com_ptr_t< _Interface > &p)
Definition: comip.h:956
bool operator==(int null, const _com_ptr_t< _InterfaceType > &p)
Definition: comip.h:942
_com_ptr_t(const _com_ptr_t &cp)
Definition: comip.h:158
constexpr auto size(const _Container &_Cont) -> decltype(_Cont.size())
Definition: xutility:1478
HRESULT CreateInstance(LPCSTR clsidStringA, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:665
int _CompareUnknown(_InterfacePtr p) const
Definition: comip.h:863
_com_ptr_t & operator=(const _variant_t &varSrc)
Definition: comip.h:325
Interface * operator->() const
Definition: comip.h:426
Interface *& GetInterfacePtr()
Definition: comip.h:596
bool operator>=(int null, const _com_ptr_t< _Interface > &p)
Definition: comip.h:1012
HRESULT _QueryInterface(_InterfacePtr p)
Definition: comip.h:836
static _Interface * GetInterfacePtr()
Definition: comip.h:44
void _Release()
Definition: comip.h:815
void __stdcall _com_issue_error(HRESULT)
_com_ptr_t(const _variant_t &varSrc)
Definition: comip.h:193
bool operator==(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:446
_com_ptr_t()
Definition: comip.h:133
_com_ptr_t(LPCSTR str, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:231
_com_ptr_t(_com_ptr_t &&cp)
Definition: comip.h:166
_com_ptr_t(LPCWSTR str, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:218
bool operator!=(int null) const
Definition: comip.h:501
Definition: comutil.h:1002
HRESULT QueryStdInterfaces(const _variant_t &varSrc)
Definition: comip.h:903
_com_ptr_t(Interface *pInterface)
Definition: comip.h:174
bool operator<=(_InterfaceType *p) const
Definition: comip.h:543
struct __declspec(uuid("00000000-0000-0000-c000-000000000046")) IUnknown
HRESULT CreateInstance(const CLSID &rclsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:604
_com_ptr_t(_In_ LPSTR str)
Definition: comip.h:104
int i[4]
Definition: dvec.h:68
#define _In_
Definition: sal.h:305
Interface * GetInterfacePtr() const
Definition: comip.h:589
#define FAILED(hr)
Definition: comutil.h:71
bool operator>=(_InterfaceType *p) const
Definition: comip.h:557
#define bool
Definition: stdbool.h:15
_com_ptr_t & operator=(Interface *pInterface)
Definition: comip.h:269
~_com_ptr_t()
Definition: comip.h:340
bool operator==(const _com_ptr_t &p) const
Definition: comip.h:469
_com_ptr_t(Interface *pInterface, bool fAddRef)
Definition: comip.h:183
_com_ptr_t & operator=(int null)
Definition: comip.h:314
bool operator==(Interface *p) const
Definition: comip.h:460
Interface * Detach()
Definition: comip.h:374
_com_ptr_t(int null)
Definition: comip.h:141
bool operator!=(_InterfaceType *p) const
Definition: comip.h:494
HRESULT CreateInstance(LPCWSTR clsidString, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:639
unsigned long DWORD
Definition: concrt.h:63
_com_ptr_t(_In_ LPWSTR str)
Definition: comip.h:111
Interface ** operator&()
Definition: comip.h:416
_com_ptr_t(_InterfaceType *p)
Definition: comip.h:92
#define GetExceptionCode
Definition: excpt.h:62
void Attach(Interface *pInterface, bool fAddRef)
Definition: comip.h:357
void Release()
Definition: comip.h:564
bool operator>=(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:550
bool operator<(_InterfaceType *p) const
Definition: comip.h:515
_com_ptr_t & operator=(const _com_ptr_t &cp)
Definition: comip.h:288
static const IID & GetIID()
Definition: comip.h:54
void Attach(Interface *pInterface)
Definition: comip.h:348
_com_ptr_t & operator=(_com_ptr_t &&cp)
Definition: comip.h:295
HRESULT GetActiveObject(const CLSID &rclsid)
Definition: comip.h:703
HRESULT QueryInterface(const IID &iid, _InterfaceType *&p)
Definition: comip.h:790
_com_ptr_t & operator=(_InterfaceType *p)
Definition: comip.h:256
_com_ptr_t & operator=(const _com_ptr_t< _OtherIID > &p)
Definition: comip.h:243
HRESULT QueryInterface(const IID &iid, _InterfaceType **p)
Definition: comip.h:802
HRESULT GetActiveObject(LPCSTR clsidStringA)
Definition: comip.h:754
Interface * m_pInterface
Definition: comip.h:810
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:984
bool operator==(int null) const
Definition: comip.h:476
#define INT_MAX
Definition: limits.h:35
bool operator>(_InterfaceType *p) const
Definition: comip.h:529
_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:728
_com_ptr_t(const CLSID &clsid, IUnknown *pOuter=NULL, DWORD dwClsContext=CLSCTX_ALL)
Definition: comip.h:205
_com_ptr_t(_com_ptr_t *p)
Definition: comip.h:119
static const IID & GetIID()
Definition: comip.h:73
void AddRef()
Definition: comip.h:577
_IIID::Interface Interface
Definition: comip.h:66
bool operator!=(const _com_ptr_t< _OtherIID > &p) const
Definition: comip.h:487