From: dushkin on
Hi all!

On VC6 this code worked perfectly:

MSXML::IXMLDOMDocumentPtr CXMLDocItem::GetXMLNode()
{
CComQIPtr<MSXML::IXMLDOMDocument> docPtr = CXMLItem::GetXMLNode();
return docPtr;
}

It is a part of Expat XML wrapping library.

But, on VS2008 it gives me the following error:

error C2664: '_com_ptr_t<_IIID>::_com_ptr_t(int)' : cannot convert
parameter 1 from 'ATL::CComQIPtr<T>' to 'int'
1> with
1> [
1> _IIID=_com_IIID<MSXML::IXMLDOMDocument,&
_GUID_2933bf81_7b36_11d2_b20e_00c04f983e60>
1> ]
1> and
1> [
1> T=MSXML::IXMLDOMDocument
1> ]
1> No user-defined-conversion operator available that can
perform this conversion, or the operator cannot be called
From: Giovanni Dicanio on
"dushkin" <taltene(a)gmail.com> wrote:

> On VC6 this code worked perfectly:
>
> MSXML::IXMLDOMDocumentPtr CXMLDocItem::GetXMLNode()
> {
> CComQIPtr<MSXML::IXMLDOMDocument> docPtr = CXMLItem::GetXMLNode();
> return docPtr;
> }
>
> It is a part of Expat XML wrapping library.
>
> But, on VS2008 it gives me the following error:
>
> error C2664: '_com_ptr_t<_IIID>::_com_ptr_t(int)' : cannot convert
> parameter 1 from 'ATL::CComQIPtr<T>' to 'int'

The _com_ptr_t constructor overload with 'int' parameter is just provided to
allow the NULL assignment (issuing an error if a non-NULL value is passed).
So, it seems to me that the VC compiler is choosing a wrong overload for
_com_ptr_t constructor.

I think the correct overload should be the one taking a COM interface
pointer (MSXML::IXMLDOMDocument *).
Have you tried like this?

return docPtr.Detach();


HTH,
Giovanni



From: Giovanni Dicanio on
"Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote:

>> On VC6 this code worked perfectly:
>>
>> MSXML::IXMLDOMDocumentPtr CXMLDocItem::GetXMLNode()
>> {
>> CComQIPtr<MSXML::IXMLDOMDocument> docPtr = CXMLItem::GetXMLNode();
>> return docPtr;
>> }
>>
>> [...]
>>
>> error C2664: '_com_ptr_t<_IIID>::_com_ptr_t(int)' : cannot convert
>> parameter 1 from 'ATL::CComQIPtr<T>' to 'int'
>
> The _com_ptr_t constructor overload with 'int' parameter is just provided
> to allow the NULL assignment (issuing an error if a non-NULL value is
> passed).
> So, it seems to me that the VC compiler is choosing a wrong overload for
> _com_ptr_t constructor.

BTW: I'm curious... is it necessary to pass to CComQIPtr?
Would it be possible to just return the result of CXMLItem::GetXMLNode?

Giovanni


From: dushkin on
On May 26, 12:59 pm, "Giovanni Dicanio"
<giovanniDOTdica...(a)REMOVEMEgmail.com> wrote:
> "dushkin" <talt...(a)gmail.com> wrote:
> > On VC6 this code worked perfectly:
>
> > MSXML::IXMLDOMDocumentPtr CXMLDocItem::GetXMLNode()
> > {
> > CComQIPtr<MSXML::IXMLDOMDocument> docPtr = CXMLItem::GetXMLNode();
> > return docPtr;
> > }
>
> > It is a part of Expat XML wrapping library.
>
> > But, on VS2008 it gives me the following error:
>
> > error C2664: '_com_ptr_t<_IIID>::_com_ptr_t(int)' : cannot convert
> > parameter 1 from 'ATL::CComQIPtr<T>' to 'int'
>
> The _com_ptr_t constructor overload with 'int' parameter is just provided to
> allow the NULL assignment (issuing an error if a non-NULL value is passed).
> So, it seems to me that the VC compiler is choosing a wrong overload for
> _com_ptr_t constructor.
>
> I think the correct overload should be the one taking a COM interface
> pointer (MSXML::IXMLDOMDocument *).
> Have you tried like this?
>
>   return docPtr.Detach();
>
> HTH,
> Giovanni

thank you Giovanni.

return docPtr.Detach() resulted with:

c:\program files\microsoft visual studio 9.0\vc\include\comip.h(852) :
error C2227: left of '->QueryInterface' must point to class/struct/
union/generic type
1> type is 'MSXML::IXMLDOMElement **'
1> c:\program files\microsoft visual studio 9.0\vc\include
\comip.h(243) : see reference to function template instantiation
'HRESULT
_com_ptr_t<_IIID>::_QueryInterface<_InterfaceType*>(_InterfacePtr)
throw()' being compiled
1> with
1> [
1> _IIID=_com_IIID<MSXML::IXMLDOMElement,&
_GUID_2933bf86_7b36_11d2_b20e_00c04f983e60>,
1> _InterfaceType=MSXML::IXMLDOMElement *,
1> _InterfacePtr=MSXML::IXMLDOMElement **
1> ]
1> d:\cm_projects\spark manager\spark manager\xml
\xmlwrapper.cpp(647) : see reference to function template
instantiation '_com_ptr_t<_IIID> &_com_ptr_t<_IIID>::operator
=<T*>(_InterfaceType *)' being compiled
1> with
1> [
1> _IIID=_com_IIID<MSXML::IXMLDOMElement,&
_GUID_2933bf86_7b36_11d2_b20e_00c04f983e60>,
1> T=MSXML::IXMLDOMElement,
1> _InterfaceType=MSXML::IXMLDOMElement *
1> ]

The issue here is that these are not classes that I wrote, but I got
them from another project, so I am not into large modifications here.
I hope the changes are minor, because the only change which caused the
problem is changing the environment and not the code.
From: dushkin on
On May 26, 12:59 pm, "Giovanni Dicanio"
<giovanniDOTdica...(a)REMOVEMEgmail.com> wrote:
> "dushkin" <talt...(a)gmail.com> wrote:
> > On VC6 this code worked perfectly:
>
> > MSXML::IXMLDOMDocumentPtr CXMLDocItem::GetXMLNode()
> > {
> > CComQIPtr<MSXML::IXMLDOMDocument> docPtr = CXMLItem::GetXMLNode();
> > return docPtr;
> > }
>
> > It is a part of Expat XML wrapping library.
>
> > But, on VS2008 it gives me the following error:
>
> > error C2664: '_com_ptr_t<_IIID>::_com_ptr_t(int)' : cannot convert
> > parameter 1 from 'ATL::CComQIPtr<T>' to 'int'
>
> The _com_ptr_t constructor overload with 'int' parameter is just provided to
> allow the NULL assignment (issuing an error if a non-NULL value is passed).
> So, it seems to me that the VC compiler is choosing a wrong overload for
> _com_ptr_t constructor.
>
> I think the correct overload should be the one taking a COM interface
> pointer (MSXML::IXMLDOMDocument *).
> Have you tried like this?
>
>   return docPtr.Detach();
>
> HTH,
> Giovanni

Giovanni, I manged to compile like this:

MSXML::IXMLDOMDocumentPtr temp;

temp.Attach(docPtr.Detach());

return temp;

Thanks!