Initialize the Signature Manager

This topic describes how to initialize the signature manager for use with an XPS document.

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

To use the Windows 7 features of the Crypto API, define the CRYPT_OID_INFO_HAS_EXTRA_FIELDS symbol as follows:

#define CRYPT_OID_INFO_HAS_EXTRA_FIELDS

Next, instantiate an IXpsSignatureManager interface by calling CoCreateInstance, as shown in the following code example.

IXpsSignatureManager    *newInterface;

// Note the implicit requirement that CoInitializeEx 
//  has previously been called from this thread.

hr = CoCreateInstance(
    __uuidof(XpsSignatureManager),
    NULL, 
    CLSCTX_INPROC_SERVER,
    __uuidof(IXpsSignatureManager),
    reinterpret_cast<LPVOID*>(&newInterface));

// make sure that you got a pointer 
// to the interface
if (SUCCEEDED(hr)) {
    // Load document into signature manager from file.
    //  xpsDocument is initialized with the file name
    //  of the document to load outside of this example.
    hr = newInterface->LoadPackageFile (xpsDocument);

    // Use newInterface

    // Release interface pointers when finished with them 
    newInterface->Release();
}    

The interface instantiated by CoCreateInstance can be used by only one XPS document, which must be loaded by calling LoadPackageFile or LoadPackageStream before calling any other method.

After the IXpsSignatureManager interface has been instantiated and an XPS document has been loaded, the signature manager is ready for use.

Next Steps

Sign a Document

Add a Signature Request to an XPS Document

Verify Document Signatures

Used in This Section

CoCreateInstance

IXpsSignatureManager

For More Information

XPS Digital Signature API Errors

XPS Document Errors

XML Paper Specification