Initialize an XPS OM

Describes how to initialize an XPS OM, which allows a program to create an XPS document.

The interfaces of the XPS Document API are created by an IXpsOMObjectFactory interface. To obtain a pointer to an IXpsOMObjectFactory that can be used in your program, call CoCreateInstance.

Before using the following code examples in your program, read the disclaimer in Common XPS Document Programming Tasks.

Code Example

The following example creates the object factory that will be used to create XPS OM interfaces in other examples.

    IXpsOMObjectFactory *xpsFactory;

    HRESULT hr = S_OK;

    // Init COM for this thread if it hasn't 
    //  been initialized, yet.
    hr = CoInitializeEx(0, COINIT_MULTITHREADED);

    hr = CoCreateInstance(

    if (SUCCEEDED(hr))
        // Make sure that you got a pointer 
        //  to the interface.

        // Use object factory...

        // ... and release when done

    // Uninitialize COM when finished

Best Practices

You can make your program more efficient by obtaining a pointer to an IXpsOMObjectFactory interface the first time that you need to call IXpsOMObjectFactory to create an interface, and then saving the pointer for use in other areas of the program. When the program no longer needs the object factory, or will not need it for a while, the pointer can be released.

Related topics

Next Steps
Create a Blank XPS OM
Used in This Section
For More Information
XPS Document API Reference
XML Paper Specification



Community Additions

© 2014 Microsoft