大网数据广告活动
打印与设备

Initialize an XPS OM

· 52CE 我爱测

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

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(
        __uuidof(XpsOMObjectFactory),
        NULL, 
        CLSCTX_INPROC_SERVER,
        __uuidof(IXpsOMObjectFactory),
        reinterpret_cast<LPVOID*>(&xpsFactory));

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

        // Use object factory...

        // ... and release when done
        xpsFactory->Release();
    }

    // Uninitialize COM when finished
    CoUninitialize();

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

IXpsOMObjectFactory

CoCreateInstance

For More Information

Packaging

XPS Document API Reference

XML Paper Specification

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。