问题描述
我卡上的问题是,我想寻求一些帮助:
I'm stuck on problem were I would like to ask for some help:
我要打印使用的ShellExecuteEx的打印动词不同类型的一些文件,并需要确保所有文件的打印顺序的任务。因此,我用FindFirstPrinterChangeNotification和FindNextPrinterChangeNotification监视使用在后台两个不同的线程,我调用的ShellExecuteEx之前启动事件PRINTER_CHANGE_ADD_JOB和PRINTER_CHANGE_DELETE_JOB,因为我不知道这将打印文件的应用程序等任何我所知道的唯一的事情就是我是唯一一个打印和文件我打印。我的解决办法似乎运作良好,我的程序成功地认识到我的文件时PRINTER_CHANGE_ADD_JOB,我甚至验证此事件是由检查什么给我额外信息通过指定JOB_NOTIFY_FIELD_DOCUMENT为我的文件印发
I have the task to print some files of different types using ShellExecuteEx with the "print" verb and need to guarantee print order of all files. Therefore I use FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification to monitor the events PRINTER_CHANGE_ADD_JOB and PRINTER_CHANGE_DELETE_JOB using two different threads in the background which I start before calling ShellExecuteEx as I don't know anything about the application which will print the files etc. The only thing I know is that I'm the only one printing and which file I print. My solution seems to work well, my program successfully recognizes the event PRINTER_CHANGE_ADD_JOB for my file, I even verify that this event is issued for my file by checking what is give to me as additional info by specifying JOB_NOTIFY_FIELD_DOCUMENT.
现在的问题是与事件PRINTER_CHANGE_DELETE_JOB,在这里我没有得到有关打印作业的另外信息,虽然我的逻辑是两个事件如出一辙:我写它只是获取与执行一个通用的线程函数它是用于该事件。我的线程承认PRINTER_CHANGE_DELETE_JOB事件,但每次调用FindNextPrinterChangeNotification每当这个事件发生时我并不在ppPrinterNotifyInfo得到任何另外的数据。这适用于启动事件,虽然,我用我的日志和调试验证。但随着PRINTER_CHANGE_DELETE_JOB我唯一得到的是NULL。
The problem now is with the event PRINTER_CHANGE_DELETE_JOB, where I don't get any addition info about the print job, though my logic is exactly the same for both events: I've written one generic thread function which simply gets executed with the event it is used for. My thread is recognizing the PRINTER_CHANGE_DELETE_JOB event, but on each call to FindNextPrinterChangeNotification whenever this event occured I don't get any addition data in ppPrinterNotifyInfo. This works for the start event, though, I verified using my logs and the debugger. But with PRINTER_CHANGE_DELETE_JOB the only thing I get is NULL.
我已经在网上搜索也有一些类似的问题,但大部分涉及到VB或者干脆没有答案的时间。我使用的是C ++项目和我的code作品为ADD_JOB事件,我不认为我做的事情完全错误的。但是,即使MSDN没有提及这一行为,我真的想确保该DELETE_JOB事件是一个为我的文件,我不能没有有关打印作业的任何信息。之后我得到的DELETE_JOB事件我的code甚至不承认其他事件,因为打印作业完成之后是确定。
I already searched the web and there are some similar questions, but most of the time related to VB or simply unanswered. I'm using a C++ project and as my code works for the ADD_JOB-event I don't think I'm doing something completely wrong. But even MSDN doesn't mention this behavior and I would really like to make sure that the DELETE_JOB event is the one for my document, which I can't without any information about the print job. After I get the DELETE_JOB event my code doesn't even recognize other events, which is OK because the print job is done afterwards.
以下是我认为是相关通知code:
The following is what I think is the relevant notification code:
WORD jobNotifyFields[1] = {JOB_NOTIFY_FIELD_DOCUMENT};
PRINTER_NOTIFY_OPTIONS_TYPE pnot[1] = {JOB_NOTIFY_TYPE, 0, 0, 0, 1, jobNotifyFields};
PRINTER_NOTIFY_OPTIONS pno = {2, 0, 1, pnot};
HANDLE defaultPrinter = PrintWaiter::openDefaultPrinter();
HANDLE changeNotification = FindFirstPrinterChangeNotification( defaultPrinter,
threadArgs->event,
0, &pno);
[...]
DWORD waitResult = WAIT_FAILED;
while ((waitResult = WaitForSingleObject(changeNotification, threadArgs->wfsoTimeout)) == WAIT_OBJECT_0)
{
LOG4CXX_DEBUG(logger, L"Irgendein Druckereignis im Thread zum Warten auf Ereignis " << LogStringConv(threadArgs->event) << L" erkannt.");
[...]
PPRINTER_NOTIFY_INFO notifyInfo = NULL;
DWORD events = 0;
FindNextPrinterChangeNotification(changeNotification, &events, NULL, (LPVOID*) ¬ifyInfo);
if (!(events & threadArgs->event) || !notifyInfo || !notifyInfo->Count)
{
LOG4CXX_DEBUG(logger, L"unpassendes Ereignis " << LogStringConv(events) << L" ignoriert");
FreePrinterNotifyInfo(notifyInfo);
continue;
}
[...]
我真的AP preciate如果任何人都可以给为什么我没有得到有关打印作业的任何数据的线索。谢谢!
I would really appreciate if anyone could give some hints on why I don't get any data regarding the print job. Thanks!
推荐答案
下面就是我认为正在发生的:
Here's what I think is going on:
我观察每个打印作业的开始和结束的两个不同的线程两个事件。与一些调试和记录我认为FindNextPrinterChangeNotification并不总是返回仅在两个不同的事件我已通知对,但在一般的一些0的事件。在这些情况下FindNextPrinterChangeNotification返回0作为在pdwChange的事件。如果我使用NOTEPAD.EXE打印一个简单的文本文件,我只得到了创建打印作业的一个事件与pdwChange值256,我需要在notifyInfo打击比较我的打印文件名称的数据,并比较两个成功。如果我打印使用当前的Acrobat Reader 11 PDF文件,我得到两个事件,一个人pdwChange为256,但提供类似本地printdatafile作为打印作业的开始的名字,这显然不是我打印的文件。第二事件具有0 pdwChange,但在notifyInfo提供的打印作业的名称是我用来打印的文件名。因为我用FreePDF测试pruproses,我想到的第一个打印机事件是我的特殊设置内部的东西。
I observe two events in two different threads for the start and end of each print job. With some debugging and logging I recognized that FindNextPrinterChangeNotification doesn't always return only the two distinct events I've notified for, but some 0-events in general. In those cases FindNextPrinterChangeNotification returns 0 as the events in pdwChange. If I print a simple text file using notepad.exe I only get one event for creation of the print job with value 256 for pdwChange and the data I need in notifyInfo to compare my printed file name against and comparing both succeeds. If I print a pdf file using current Acrobat Reader 11 I get two events, one has pdwChange as 256, but gives something like "local printdatafile" as the name of the print job started, which is obviously not the file I printed. The second event has a pdwChange of 0, but the name of the print job provided in notifyInfo is the file name I used to print. As I use FreePDF for testing pruproses, I think the first printer event is something internal to my special setup.
打印作业的删除通知内容创建0的事件了。这一次,那些FindNextPrinterChangeNotification之前发送的pdwChange返回1024并及时打印作业开始后的很接近。在这种情况下,只有一个产生0事件包含notifyInfo以等于我开始打印的文件名的文件名。 0活动结束后有整整1024 pdwChange额外的事件,但没有对notifyInfo任何数据。
The notifications for the deletion of a print job create 0 events, too. This time those are sent before FindNextPrinterChangeNotification returns 1024 in pdwChange, and timely very close after the start of the print job. In this case the exactly one generated 0 event contains notifyInfo with a document name which equals the file name I started printing. After the 0 event there's exactly one additional event with pdwChange of 1024, but without any data for notifyInfo.
我认为Windows正在使用某种机制作为初始事件之后0个事件已与它发射它提供了相同事件的其他通知的真正价值与通知的用户,例如256 PRINTER_CHANGE_ADD_JOB。在另一方面,似乎有些0个事件只是解雇了为即将到来的事件,然后获取的例如真正的价值提供数据1024 PRINTER_CHANGE_DELETE_JOB,但没有再数据,因为这已经被递送到事件消费者具有非常早0事件。喜欢的东西看,还有更多在过去的事件。和看,有些事情是会用我现在已经提供数据的情况发生。实施这样的做法我版画现在似乎按预期方式工作。
I think Windows is using some mechanism which provides additional notifications for the same event as 0 events after the initial event has been fired with it's real value the user notified with, e.g. 256 for PRINTER_CHANGE_ADD_JOB. On the other hand it seems that some 0 events are simply fired to provide data for an upcoming event which then gets the real value of e.g. 1024 for PRINTER_CHANGE_DELETE_JOB, but without anymore data because that has already been delivered to the event consumer with a very early 0 event. Something like "Look, there's more for the last events." and "Look, something is going to happen with the data I already provide now." Implementing such an approach my prints now seem to work as expected.
当然我写的不适合到什么是记录了FindNextPrinterChangeNotification,但它使一个有点道理给我。 ; - )
Of course what I wrote doesn't fit to what is documented for FindNextPrinterChangeNotification, but it makes a bit of sense to me. ;-)
这篇关于FindNextPrinterChangeNotification为ppPrinterNotifyInfo返回NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!