Error C2227 when compiling with XML Support

Posted on 2007-10-12
Last Modified: 2013-12-14
I have inherited a Visual C++ application. I am using Visual Studio 2005. It is *not* a .NET app. Whenever I compile I get 3 errors that read thus:

Error 476 error C2227: left of '->QueryInterface' must point to class/struct/union/generic type C:\Program Files\Microsoft Visual Studio 8\VC\include\comip.h 852

I have three lines that make a call like this in various placess:

::IXMLDOMDocumentPtr pXMLDoc = (MSXML2::IXMLDOMDocumentPtr)GetDocument();

If I comment out the "(MSXML2::IXMLDOMDocumentPtr)GetDocument();" it compiles fine. Of course, pXMLDoc is then not initialized. Now, this GetDocument() function signature is like:

void* CXMLInterface::GetDocument()

Even if I comment out all of the code in that function and then just make it "return 0;" I still get the error.

Now, if you look at that original error it is in comip.h. That apparently is a standard include file. I have not modified that include file, it is stock. I don't know why there would be any problem with it. Googling this yields very little. The  best I can come up with is that there is a mismatch in some kind of include file set between the SDK and the VS standard include set.

At the top of the file I have
#import <MSXML3.dll>

I also include a msxml.h which appears to have been generated, of course. This is the beginning of that file

// Created by Microsoft (R) C/C++ Compiler Version 14.00.50727.42 (67f0d8d7).
// c:\tmp\cacat\cacat\debug\msxml.tlh
// C++ source equivalent of Win32 type library msxml.dll
// compiler-generated file created 10/07/06 at 14:30:45 - DO NOT EDIT!

I don't have that c:\tmp\cacat\.... file. Again this stuff was inherited and there is not anyone else I can talk to about it. It appears all this is just due to the XML stuff. So if anyone can give me the best route to get this solve ASAP I would really really appreciate it. Thanks.
Question by:NetworkArchitek
    LVL 12

    Accepted Solution

    Try the following:
    IXMLDOMDocument* pDomDoc = (IXMLDOMDocument*)GetDocument();
    ::IXMLDOMDocumentPtr pXMLDoc = pDomDoc;

    Because IxxxPtr is a smart pointer and will call QueryInterface() in its ctor, but it is not available in (void*) type.
    LVL 10

    Author Comment

    Hey thanks, we're making a little progress I think. I made that change in two places and it got rid of that error. Now this line:

    vbRetVal= pXMLDoc->load(variant);

    creates error C2660: 'IXMLDOMDocument::load' " function does not take 1 arguments

    I clicked on "Go to Definition" for the load() function and it is in the generated msxml.h. This is what it says in that header file

        VARIANT_BOOL load (
            const _variant_t & xmlSource );

    That looks like one argument to me ... Any ideas? Thanks
    LVL 12

    Expert Comment

    what is the type of pXMLDoc?
    if type is IXMLDOMDocument*, then you have to call it in the following way:
    pXMLDoc->load(variant, &b);

    if type is IXMLDOMDocumentPtr, your code looks like fine.

    There are some MSXML tutorials in this web site:

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now