Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using MSXML APIs in C++ program

Using MSXML APIs in C++ program

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++xml
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koumodaki
    wrote on last edited by
    #1

    I have a C++ Program which in which I have to read a XML file contents. The code is #include "fstream.h" #include "string.h" #import "msxml2.dll" named_guids raw_interfaces_only using namespace MSXML2; using namespace std; void main() { IXMLDOMDocumentPtr m_pXmlDoc; IXMLDOMNodePtr m_pProductNode; HRESULT hr = m_pXmlDoc.CreateInstance(MSXML2::CLSID_DOMDocument); _variant_t vtFileName("my_xml.xml"); VARIANT_BOOL vtRetVal; m_pXmlDoc->load(vtFileName,&vtRetVal); } The CreateInstance() call fails and m_pXmlDoc is NULL. Why am I not getting the instance? What is wrong in this piece of code?

    D J 2 Replies Last reply
    0
    • K koumodaki

      I have a C++ Program which in which I have to read a XML file contents. The code is #include "fstream.h" #include "string.h" #import "msxml2.dll" named_guids raw_interfaces_only using namespace MSXML2; using namespace std; void main() { IXMLDOMDocumentPtr m_pXmlDoc; IXMLDOMNodePtr m_pProductNode; HRESULT hr = m_pXmlDoc.CreateInstance(MSXML2::CLSID_DOMDocument); _variant_t vtFileName("my_xml.xml"); VARIANT_BOOL vtRetVal; m_pXmlDoc->load(vtFileName,&vtRetVal); } The CreateInstance() call fails and m_pXmlDoc is NULL. Why am I not getting the instance? What is wrong in this piece of code?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      koumodaki wrote:

      The CreateInstance() call fails...

      And the value of hr would be what?


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      K 1 Reply Last reply
      0
      • K koumodaki

        I have a C++ Program which in which I have to read a XML file contents. The code is #include "fstream.h" #include "string.h" #import "msxml2.dll" named_guids raw_interfaces_only using namespace MSXML2; using namespace std; void main() { IXMLDOMDocumentPtr m_pXmlDoc; IXMLDOMNodePtr m_pProductNode; HRESULT hr = m_pXmlDoc.CreateInstance(MSXML2::CLSID_DOMDocument); _variant_t vtFileName("my_xml.xml"); VARIANT_BOOL vtRetVal; m_pXmlDoc->load(vtFileName,&vtRetVal); } The CreateInstance() call fails and m_pXmlDoc is NULL. Why am I not getting the instance? What is wrong in this piece of code?

        J Offline
        J Offline
        jhwurmbach
        wrote on last edited by
        #3

        Try

        HRESULT hr = m_pXmlDoc.CreateInstance( __uuidof(MSXML2::DOMDocument40));

        This way, you ask explicitly for a DOM document version 4.


        Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
        George Orwell, "Keep the Aspidistra Flying", Opening words

        K 1 Reply Last reply
        0
        • D David Crow

          koumodaki wrote:

          The CreateInstance() call fails...

          And the value of hr would be what?


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          K Offline
          K Offline
          koumodaki
          wrote on last edited by
          #4

          On my PC hr = -2147221008 while debugging......guess its some junk value

          D M 2 Replies Last reply
          0
          • J jhwurmbach

            Try

            HRESULT hr = m_pXmlDoc.CreateInstance( __uuidof(MSXML2::DOMDocument40));

            This way, you ask explicitly for a DOM document version 4.


            Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
            George Orwell, "Keep the Aspidistra Flying", Opening words

            K Offline
            K Offline
            koumodaki
            wrote on last edited by
            #5

            I get an error while compiling. error C2039: 'DOMDocument40' : is not a member of 'MSXML2' error C2065: 'DOMDocument40' : undeclared identifier Could you please tell me th eproper file to include?

            J 1 Reply Last reply
            0
            • K koumodaki

              On my PC hr = -2147221008 while debugging......guess its some junk value

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              It appears you have failed to call CoInitialize().


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              K 1 Reply Last reply
              0
              • K koumodaki

                I get an error while compiling. error C2039: 'DOMDocument40' : is not a member of 'MSXML2' error C2065: 'DOMDocument40' : undeclared identifier Could you please tell me th eproper file to include?

                J Offline
                J Offline
                jhwurmbach
                wrote on last edited by
                #7

                *I* do

                #import "../thirdparty/msxmlbase/msxmlinclude/msxml2.tlb" named_guids

                but the path will be totally different for you.


                Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                George Orwell, "Keep the Aspidistra Flying", Opening words

                1 Reply Last reply
                0
                • K koumodaki

                  On my PC hr = -2147221008 while debugging......guess its some junk value

                  M Offline
                  M Offline
                  Michael Dunn
                  wrote on last edited by
                  #8

                  You have guessed wrong. Use the Error Lookup tool to get the description of that error.

                  --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Hungarian notation FTW

                  L 1 Reply Last reply
                  0
                  • D David Crow

                    It appears you have failed to call CoInitialize().


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    K Offline
                    K Offline
                    koumodaki
                    wrote on last edited by
                    #9

                    Thanks David. I had not called CoInitialize(). It works now.:)

                    1 Reply Last reply
                    0
                    • M Michael Dunn

                      You have guessed wrong. Use the Error Lookup tool to get the description of that error.

                      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Hungarian notation FTW

                      L Offline
                      L Offline
                      led mike
                      wrote on last edited by
                      #10

                      Michael Dunn wrote:

                      You have guessed wrong.

                      Well that hardly ever happens.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups