码迷,mamicode.com
首页 > 编程语言 > 详细

C++ 打印XPS文档

时间:2019-07-27 18:22:41      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:filename   stat   tar   hresult   close   col   wait   ali   uuid   

 1 CoInitializeEx(0, COINIT_MULTITHREADED);
 2 
 3 IXpsOMObjectFactory *xpsFactory;
 4 
 5 HRESULT hr = CoCreateInstance(__uuidof(XpsOMObjectFactory), NULL, CLSCTX_INPROC_SERVER,__uuidof(IXpsOMObjectFactory),reinterpret_cast<LPVOID*>(&xpsFactory));
 6 
 7 IXpsOMPackage *package = NULL;
 8 
 9 std::tstring tstrFilename = _T("C:\\MyXPSFile.xps");
10 
11 hr = xpsFactory->CreatePackageFromFile((LPCTSTR)tstrFilename.c_str(),FALSE,&package);
12 
13 HANDLE completionEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
14 
15 IXpsPrintJob *job = NULL;
16 IXpsPrintJobStream *jobStream = NULL;
17 
18 StartXpsPrintJob(_T("MyPrinter"),_T("Print Job 1"), NULL, NULL, completionEvent, NULL, 0, &job, &jobStream, NULL);
19 
20 hr = package->WriteToStream (jobStream, FALSE);
21 
22 hr = jobStream->Close();
23 
24 if (completionEvent != NULL)
25 {
26    if (WaitForSingleObject(completionEvent, INFINITE) == WAIT_OBJECT_0)
27    {
28       XPS_JOB_STATUS jobStatus;
29       hr = job->GetJobStatus(&jobStatus);
30    }
31 
32    CloseHandle(completionEvent);
33    completionEvent = NULL;
34 }
35 
36 jobStream->Release();
37 jobStream = NULL;
38 
39 job->Release();
40 job = NULL;
41 
42 package->Release();
43 package = NULL;

 

C++ 打印XPS文档

标签:filename   stat   tar   hresult   close   col   wait   ali   uuid   

原文地址:https://www.cnblogs.com/guozht/p/11256090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!