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

Set Up My Visual C++ Project

For simplicity and clarity, the C/C++ applications presented in this tutorial are constructed as Win32 console application projects in Microsoft Visual Studio. The procedure below outlines the steps to build and run such a project.

To create a new Win32 console application project

  1. Start Visual C++.
  2. From the File menu, select New. On the Projects tab of the New dialog box that appears, select Win32 Console Application in the left pane. Then type the name of the project (in this case, "trivialProj") in the Project name field. For the project Location field, either accept the default setting or choose another location (e.g., c:\examples\HowDoI). Click OK.
  3. The Win32 Console Application property page will appear. For the type of Console Application, select An empty project and click Finish. When the New Project Information box displays, click OK.

Now you are ready to add source, header, and resource files to the project. For a clear illustration, each task in the How Do I Program with DOM in C++ tutorial is implemented as a standalone Win32 console application. The following skeleton code shows the general layout of these applications.

Source Listing for a Trivial Application (trivial.cpp)

#include <stdio.h>
#import <msxml5.dll> raw_interfaces_only
using namespace MSXML2;
int main(int argc, char* argv[])
{
   CoInitialize(NULL);
   printf("start using msxml5.dll... \n");
   // Add your comments here.
...CoUninitialize();
   return 0;
}

To add source code to your project

  1. Select FileView on the project browser, and highlight your project files (in this case, trivialProj files). From the File menu, select New.
  2. On the Files tab of the New dialog box, highlight C++ Source File. Then type the name of the C++ source file (in this case, "trivial.cpp") in the File name text box.
  3. Click OK.
  4. Copy the source code snippet above and paste it into the file you've just created.
    Note   Before using any COM module, you must initialize the COM library by calling the CoInitialize(NULL) function in your application. You then must close the COM library by calling the CoUninitialize() function before the application exits.

To build and run the application

  1. To test the application while in the development environment, select Build TrivialProj.exe from the Build menu.
  2. When the application is built without errors, run the application by selecting !Execute TrivialProj.exe from the Build menu.

When you build and run trivial.cpp, you should get the following output:

start using msxml5.dll...

Now we are ready start working with XML DOM. First, we'll demonstrate how to include headers and libraries manually.