comhelper.h

来自「这是国外的resip协议栈」· C头文件 代码 · 共 112 行

H
112
字号
#ifndef COMHelper_h#define COMHelper_h#pragma warning( push)#pragma warning( disable: 4786)#pragma warning( disable: 4290)#include <new>#include <typeinfo>#include <comdef.h>#include <comip.h>namespace COMUtility{// simple template to reduce the typing effort when doing reinterpret<void**> caststemplate< typename Interface>  inline void** ppvoid( Interface **ppInterface){  return reinterpret_cast< void**>( ppInterface);}template< typename Interface>  inline GUID* piid( const Interface* pInterface){  return __uuidof( pInterface);}// to be used with _com_ptr_t, uses function overloadingtemplate< typename InterfacePtr>  inline GUID* piid( const InterfacePtr& pInterface){  return const_cast< GUID*>( &pInterface.GetIID());}template< typename Interface>  inline const GUID& riid( const Interface* pInterface){  return *__uuidof( pInterface);}// to be used with _com_ptr_t, use function overloadingtemplate< typename InterfacePtr>  inline const GUID& riid( const InterfacePtr& pInterface){  return pInterface.GetIID();}// this is used for regular COM interface pointerstemplate < class rawTargetInterface, class rawSourceInterface>  inline rawTargetInterface* interface_cast( rawSourceInterface* pSrcInterface) throw( std::bad_cast){  rawTargetInterface* pTargetInterface = NULL;  if ( SUCCEEDED( pSrcInterface->QueryInterface( __uuidof( pTargetInterface),                                                 reinterpret_cast<void**>(&pTargetInterface))))    return pTargetInterface;  else    throw std::bad_cast();}// non-throwing versions of the same - need to use parameter std::nothrow on function calltemplate < class rawTargetInterface, class rawSourceInterface>  inline rawTargetInterface* interface_cast( const std::nothrow_t&,                                             rawSourceInterface* pSrcInterface) throw(){  rawTargetInterface* pTargetInterface = NULL;  pSrcInterface->QueryInterface( __uuidof( pTargetInterface),                                 reinterpret_cast<void**>(&pTargetInterface));  return pTargetInterface;}// Is probably best used as a static member of the class, so it's// accessible everywhereclass COMExceptionThrower{public:	COMExceptionThrower( void){}	~COMExceptionThrower( void){}	COMExceptionThrower( const HRESULT errCode)	{		this->operator=( errCode);	}		protected:	// don't allow regular copy constructor call	COMExceptionThrower( const COMExceptionThrower&);public:	inline const COMExceptionThrower& operator=( const HRESULT errCode) const throw( _com_error)	{		if ( FAILED( errCode))			_com_raise_error( errCode);					return *this;	}};} // end namespace COMUtility#pragma warning( pop) #endif // COMHelper_h

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?