
ATL object containing COM object
(LPOLESTR)("microsoft.xmldom") doesn't make it a Unicode string - it
makes it a garbage in Unicode ("mi" is interpreted as one Unicode
character, then "cr" and so on, and no telling how long the string is
thought to be because Unicode string is terminated by two zero bytes).
You need
OLESTR("microsoft.xmldom")
which on Win32 platforms expands into L"microsoft.xmldom". As to
aggregation, CComPtr::CoCreateInstance accepts pUnkOuter parameter
where you are supposed to pass your IUnknown, and see also
COM_INTERFACE_ENTRY_AGGREGATE and COM_INTERFACE_ENTRY_AGGREGATE_BLIND
--
With best wishes,
Igor Tandetnik
Quote:
> I am trying to write an ATL object that imports
> and contains a COM object and cannot get the
> following to create an instance of the contained
> object.
> What is the correct way to do this, preferably
> with and without aggregation?
> Thanks.
> // DOMContaner.h : Declaration of the CDOMContainer
> #ifndef __DOMCONTAINER_H_
> #define __DOMCONTAINER_H_
> #include "resource.h" // main symbols
> #import "msxml.dll"
//////////////////////////////////////////////////////////////////////
///////
Quote:
> // CDOMContainer
> class ATL_NO_VTABLE CDOMContainer :
> public CComObjectRootEx<CComSingleThreadModel>,
> public CComCoClass<CDOMContainer, &CLSID_DOMContainer>,
> public ISupportErrorInfo,
> public IConnectionPointContainerImpl<CDOMContainer>,
> public IDispatchImpl<IDOMContainer, &IID_IDOMContainer,
> &LIBID_DOMContainerLib>
> {
> public:
> CDOMContainer()
> {
> }
> DECLARE_REGISTRY_RESOURCEID(IDR_DOMCONTAINER)
> DECLARE_PROTECT_FINAL_CONSTRUCT()
> BEGIN_COM_MAP(CDOMContainer)
> COM_INTERFACE_ENTRY(IDOMContainer)
> COM_INTERFACE_ENTRY(IDispatch)
> COM_INTERFACE_ENTRY(ISupportErrorInfo)
> COM_INTERFACE_ENTRY(IConnectionPointContainer)
> END_COM_MAP()
> BEGIN_CONNECTION_POINT_MAP(CDOMContainer)
> END_CONNECTION_POINT_MAP()
> HRESULT FinalConstruct()
> {
> HRESULT hr = S_OK;
> hr = m_spDOM.CoCreateInstance( (LPOLESTR)("microsoft.xmldom") );
> return hr;
> }
> void FinalRelease()
> {
> m_spDOM.Release();
> }
> // ISupportsErrorInfo
> STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
> // IDOMContainer
> public:
> protected:
> CComPtr< MSXML::IXMLDOMDocument > m_spDOM;
> };
> #endif file://__DOMCONTAINER_H_