user3360310
user3360310

Reputation: 457

cannot convert parameter 1 from 'ATL::CComPtr<T>' to 'int'

I'm migrating a project from vs 6.0 to vs 2008, I get the following error,

error C2664: '_com_ptr_t<_IIID>::_com_ptr_t(int)' : cannot convert parameter 1 from 'ATL::CComPtr' to 'int'

Output Window:

with
    [
        _IIID=_com_IIID<XML::IXMLDOMNode,& _GUID_2933bf80_7b36_11d2_b20e_00c04f983e60>
    ]
    and
    [
        T=XML::IXMLDOMNode
    ]

I am not able to fix this issue. The same is working fine in vs 6.0, I do understand that lot of things has changed from vs 6.0 to vs 2008.

Details on the error below:

bool CXMLHelper::GetFirstSubRecord()
{
bool bFound = false;

if ( m_spXMLNode == NULL ) return false;
if ( VARIANT_TRUE == m_spXMLNode->hasChildNodes() )
{
    typedef object_iterator<XML::IXMLDOMNode> iterator;
    for ( iterator oIte(m_spXMLNode->childNodes); oIte != iterator(); ++oIte )
    {
        XML::IXMLDOMNodePtr spNode(*oIte); // c2664 error
        if ( spNode->hasChildNodes() && !CXMLHelper::HasTextChild(spNode) )
        {

            m_spXMLNode = spNode;
            bFound = true;
            break; 
        }
    }
}
return bFound;
}

Definition of IXMLDOMNodePt:

_COM_SMARTPTR_TYPEDEF(IXMLDOMNode, __uuidof(IXMLDOMNode));

I understand that the error is because compiler not able to convert oIte from 'ATL::CComPtr' to 'int'. I'm very new to COM, Any help to fix this error is greatly appreciated. Thanks a lot in advance.

Regards, Ankush.

Upvotes: 2

Views: 1016

Answers (1)

sharptooth
sharptooth

Reputation: 170499

The problem is that for some reason *oIte is of type ATL::CComPtr and _com_ptr_t (type of the template pointer spNode) has no constructor accepting CComPtr& but instead it has two constructors one accepting int and the other accpting Interface* and the compiler can't select the proper one. You have to explicitly say to the compiler that you want the constructor accepting Interface* and to achieve that you have to tell it to extract the encapsulated Interface* which is stored in member variable CComPtr::p:

XML::IXMLDOMNodePtr spNode((*oIte).p);

Upvotes: 3

Related Questions