/** \file * Global Interface Table wrapper. */ /* * Copyright © 2000, 2001 Sofus Mortensen * * This material is provided "as is", with absolutely no warranty * expressed or implied. Any use is at your own risk. Permission to * use or copy this software for any purpose is hereby granted without * fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is * granted, provided the above notices are retained, and a notice that * the code was modified is included with the above copyright notice. * * This header is part of Comet version 2. * https://github.com/alamaison/comet */ #ifndef COMET_GIT_H #define COMET_GIT_H #include #include namespace comet { /*! \addtogroup COMType */ //@{ class GIT; /// Type-safe GIT Cookie. template class GIT_cookie { friend class GIT; public: GIT_cookie(const GIT_cookie& c) : cookie_(c.cookie_) {} explicit GIT_cookie(DWORD c) : cookie_(c) {} GIT_cookie() : cookie_(0) {} DWORD get_cookie() const { return cookie_; } private: DWORD cookie_; }; /// Global Interface Table wrapper. class GIT { public: GIT() : git_(CLSID_StdGlobalInterfaceTable) {} /** Register Interface in the GIT. * \param ptr Interface to register. * \return Type-safe cookie. */ template GIT_cookie register_interface(com_ptr const & ptr) { DWORD cookie; git_->RegisterInterfaceInGlobal(ptr.get(), uuidof(), &cookie) | raise_exception; return GIT_cookie(cookie); } /** Retrieve Interface in the GIT. * \param c Cookie * \return Marshalled interface. */ template com_ptr get_interface(GIT_cookie const& c) { Itf* itf; git_->GetInterfaceFromGlobal(c.get_cookie(), uuidof(), reinterpret_cast(&itf)) | raise_exception; return auto_attach(itf); } /** Revoke the cookie from the GIT. * \param c Cookie. */ template void revoke_interface(GIT_cookie const& c) { HRESULT hr = git_->RevokeInterfaceFromGlobal(c.get_cookie()); hr; assert(SUCCEEDED(hr)); } private: com_ptr< ::IGlobalInterfaceTable> git_; }; //@} } // namespace comet #endif