初始化簽章管理員

本主題描述如何初始化簽章管理員以搭配 XPS 檔使用。

在程式中使用下列程式碼範例之前,請先閱讀一般數位簽章程式設計 工作中的 免責聲明。

若要使用密碼編譯 API 的 Windows 7 功能,請定義 CRYPT_OID_INFO_HAS_EXTRA_FIELDS 符號,如下所示:

#define CRYPT_OID_INFO_HAS_EXTRA_FIELDS

接下來,藉由呼叫 CoCreateInstance 來具現化 IXpsSignatureManager 介面,如下列程式碼範例所示。

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();
}    

CoCreateInstance 具現化的介面只能由一個 XPS 檔使用,在呼叫任何其他方法之前,必須先呼叫 LoadPackageFile LoadPackageStream 來載入它。

在具現化 IXpsSignatureManager 介面並載入 XPS 檔之後,簽章管理員便已可供使用。

後續步驟

簽署檔

將簽章要求新增至 XPS 檔

驗證檔簽章

用於本節

CoCreateInstance

IXpsSignatureManager

詳細資訊

XPS 數位簽章 API 錯誤

XPS 檔錯誤

XML 紙張規格