Get Ready to Work with MSXML (Smart)

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Developer's Guide

Get Ready to Work with MSXML (Smart)

Programming with MSXML in C/C++ with smart pointer class wrappers requires the same basic components as programming without smart pointer class wrappers:

  • An appropriate version of MSXML installed on your machine.
  • The MSXML libraries and headers incorporated into your project.

See Get Ready to Work with MSXML (C/C++) and Set Up My Visual C++ Project for instructions on how to install these components and use them in Visual C++.

This topic describes how to incorporate headers and libraries into your project.

Importing Headers and Libraries

After MSXML is installed, you need to set up your application project so that calls to the MSXML-supported APIs are resolved properly when the application is built. In Microsoft Visual C++, you must import the MSXML headers and libraries into your project. This is a fairly simple task if you intend to use smart pointer classes to access interface pointers.

Calling Interfaces Using Smart Pointer Classes

If you use the DOM interfaces through their smart pointer class wrappers, you can simply insert the following statements at the beginning of your application code:

#import <msxml5.dll>
using namespace MSXML2;

The first statement instructs Visual C++ to generate the type library information contained in the msxml5.dll library. As a result, two header files, msxml5.tlh and msxml5.tli, are created in one of your project's folders. These files contain the required type library information, with interfaces also wrapped in smart pointer classes. You might find it helpful to examine the *.tlh and *.tli files if you have not used them before. The second statement imports the namespace to your project, so that you can reference the DOM APIs without specifying their namespace explicitly.

Using Smart Pointer Classes

There are many advantages to using smart pointer classes. In addition to automating some object management tasks, such as calling the AddRef method or the Release method on an interface pointer, they make the API calling convention in C/C++ more consistent with that in script or Visual Basic. This is helpful to programmers who frequently use these languages.

You might want to use the raw COM interface pointers when performance is an important issue. The Program with DOM in C/C++ tutorial shows you how to do that.

The syntax used to call the XML DOM methods or properties using smart pointer classes differs from that using raw interface pointers. The following topics provide more information about using smart pointer classes.