/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Microsoft Windows Copyright (C) Microsoft Corporation, 1995 - 1999 File: CopyItem.h Content: Declaration of _CopyXXXItem template class. History: 11-15-99 dsie created ------------------------------------------------------------------------------*/ #ifndef __CopyItem_H_ #define __CopyItem_H_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include #pragma warning(disable:4786) // Disable symbol names > 256 character warning. // // _CopyMapItem class. // template class _CopyMapItem { public: // // copy method. // static HRESULT copy(VARIANT * p1, std::pair > * p2) { CComPtr p = p2->second; CComVariant var = p; return VariantCopy(p1, &var); } // // init method. // static void init(VARIANT * p) { p->vt = VT_EMPTY; } // // destroy method. // static void destroy(VARIANT * p) { VariantClear(p); } }; // // _CopyBstrMap class. // class _CopyClsIdMap { public: // // copy method. // static HRESULT copy(VARIANT * p1, std::pair * p2) { HRESULT hr; CComPtr p; // // Create the decoder object. // if (S_OK == (hr = ::CoCreateInstance((REFCLSID) p2->second, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (LPVOID *) &p))) { // // Copy. // p1->vt = VT_DISPATCH; hr = p->QueryInterface((IDispatch **) &(p1->pdispVal)); } return hr; } // // init method. // static void init(VARIANT * p) { p->vt = VT_EMPTY; } // // destroy method. // static void destroy(VARIANT * p) { VariantClear(p); } }; template class _CopyVariant { public: // // init method. // static void init(VARIANT * p) { p->vt = VT_EMPTY; } // // copy method. // static HRESULT copy(VARIANT * p1, T * p2) { CComVariant var = *p2; return VariantCopy(p1, &var); } // // destroy method. // static void destroy(VARIANT * p) { VariantClear(p); } }; #if (0) //DSIE template class GenericCopy { public : typedef DestinationType destination_type; typedef SourceType source_type; static void init(destination_type* p) { _Copy::init(p); } static void destroy(destination_type* p) { _Copy::destroy(p); } static HRESULT copy(destination_type* pTo, const source_type* pFrom) { return _Copy::copy(pTo, const_cast(pFrom)); } }; // class GenericCopy template <> class GenericCopy { public : typedef VARIANT destination_type; typedef std::string source_type; static void init(destination_type* p) { GenericCopy::init(p); } static void destroy(destination_type* p) { GenericCopy::destroy(p); } static HRESULT copy(destination_type* pTo, const source_type* pFrom) { return CComVariant(pFrom->c_str()).Detach(pTo); } }; // class GenericCopy template <> class GenericCopy { public : typedef BSTR destination_type; typedef std::string source_type; static void init(destination_type* p) { GenericCopy::init(p); } static void destroy(destination_type* p) { GenericCopy::destroy(p); } static HRESULT copy(destination_type* pTo, const source_type* pFrom) { *pTo = CComBSTR(pFrom->c_str()).Detach(); if (*pTo) return S_OK; else return E_OUTOFMEMORY; } }; // class GenericCopy #endif //DSIE #endif // __CopyItem_H_