PrintDriver V4 event handling
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
PrintDriver V4 event handling
Hello.
Can you tell me how to handle print events, such as OnStartDoc, OnStartPage and so on.
I try in this way:
-Implement _IPXCPrinterEvents interface
-Ask IConnectionPointContainer at PXCComLib::IPXCControlEx object
-Make Advise
-Send document on print trough application
-Wait for ivents
Please tell me what is wrong.
Can you tell me how to handle print events, such as OnStartDoc, OnStartPage and so on.
I try in this way:
-Implement _IPXCPrinterEvents interface
-Ask IConnectionPointContainer at PXCComLib::IPXCControlEx object
-Make Advise
-Send document on print trough application
-Wait for ivents
Please tell me what is wrong.
- Ivan - Tracker Software
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
- Contact:
- Ivan - Tracker Software
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
- Contact:
In this case what you need to do:
1. add into your stdafx.h
2. declare a class like this (or you can use existing class):
HTH
1. add into your stdafx.h
Code: Select all
#import "progid:PXCComLib.CPXCControlEx" rename_namespace("PXC"), named_guids
Code: Select all
class MyPXCHandler : public IDispEventImpl<0, MyPXCHandler, &__uuidof(PXC::_IPXCPrinterEvents), &PXC::LIBID_PXC, 1, 0>
{
public:
MyPXCHandler()
{
m_pFactory = NULL;
m_pPrinter = NULL;
}
~MyPXCHandler()
{
Finish();
}
public:
HRESULT Prepare()
{
if (m_pPrinter != NULL)
return S_OK;
if (m_pFactory == NULL)
{
m_pFactory = PXC::IPXCControlExPtr(__uuidof(PXC::CPXCControlEx));
if (m_pFactory == NULL)
{
// handle error here
return E_FAIL;
}
}
m_pPrinter = m_pFactory->Printer[L"", L"PDF-XChange 4.0 Sample", L"<YOUR REG KEY HERE>", L"<YOUR DEV CODE HERE>"];
if (m_pPrinter == NULL)
return E_FAILE;
return DispEventAdvise(m_pPrinter);
}
HRESULT Finish()
{
if (m_pPrinter != NULL)
{
m_pPrinter->RestoreDefaultPrinter();
DispEventUnadvise(m_pPrinter);
m_pPrinter.Release();
}
if (m_pFactory != NULL)
{
m_pFactory.Release();
}
}
public:
BEGIN_SINK_MAP(CMainDlg)
SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 1, OnStartDoc)
SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 2, OnStartPage)
SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 3, OnEndPage)
SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 4, OnEndDoc)
SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 5, OnFileSaved)
SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 6, OnFileSent)
SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 7, OnError)
SINK_ENTRY_EX(0, __uuidof(PXC::_IPXCPrinterEvents), 8, OnDocSpooled)
END_SINK_MAP()
public:
HRESULT __stdcall OnStartDoc(long JobID, BSTR lpszDocName, BSTR lpszAppName);
HRESULT __stdcall OnStartPage(long JobID, long nPageNumber)
{
// add your handling here
return S_OK;
}
HRESULT __stdcall OnEndPage(long JobID, long nPageNumber)
{
// add your handling here
return S_OK;
}
HRESULT __stdcall OnEndDoc(long JobID, long bOK)
{
// add your handling here
return S_OK;
}
HRESULT __stdcall OnFileSaved(long JobID, BSTR lpszFileName)
{
// add your handling here
return S_OK;
}
HRESULT __stdcall OnFileSent(long JobID, BSTR lpszFileName)
{
// add your handling here
return S_OK;
}
HRESULT __stdcall OnError(long JobID, long dwErrorCode)
{
// add your handling here
return S_OK;
}
HRESULT __stdcall OnDocSpooled(long JobID, BSTR lpszDocName, BSTR lpszAppName)
{
// add your handling here
return S_OK;
}
public:
PXC::IPXCPrinterPtr m_pPrinter;
PXC::IPXCControlExPtr m_pFactory;
};
Tracker Software (Project Director)
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
- John - Tracker Supp
- Site Admin
- Posts: 5219
- Joined: Tue Jun 29, 2004 10:34 am
- Location: United Kingdom
- Contact:
Pleasure.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.
Best regards
Tracker Support
http://www.tracker-software.com
Best regards
Tracker Support
http://www.tracker-software.com
Hello!
There is one problem:
I print document through Internet Explorer (programmatically) and call RestoreDefaultPrinter while handling OnStartDoc event.
Then when the document is printed and displayed the printer's progress bar still visible with "Saving PDF... 100% done" and my program hangs on DispEventUnadvise, somewhere deep in ntdll.dll.
If in function HRESULT Finish() I make Sleep(1000) all work right, if I call RestoreDefaultPrinter as you write all work right too.
So, why the deadlock occurs?
There is one problem:
I print document through Internet Explorer (programmatically) and call RestoreDefaultPrinter while handling OnStartDoc event.
Then when the document is printed and displayed the printer's progress bar still visible with "Saving PDF... 100% done" and my program hangs on DispEventUnadvise, somewhere deep in ntdll.dll.
If in function HRESULT Finish() I make Sleep(1000) all work right, if I call RestoreDefaultPrinter as you write all work right too.
So, why the deadlock occurs?
- Ivan - Tracker Software
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
- Contact:
Can you try to call Finish from OnDocSpooled, but not from OnDocStart ? OnDocSpooled is synchronous event while OnDocStart isn't.
Tracker Software (Project Director)
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
I didn't call Finish() from OnStartDoc event, I've called RestoreDefaultPrinter() only from OnDocStart. Finish() was called after OnFileSaved event being processed.Ivan - Tracker Software wrote:Can you try to call Finish from OnDocSpooled, but not from OnDocStart ? OnDocSpooled is synchronous event while OnDocStart isn't.
But if I call Finish() in OnDocSpooled event handling, as you say, then the programm hangs on m_pPrinter.Release() call.
Actually I wasn't right in previous post when say that program hangs on DispEventUnadvise, it was hanging on m_pPrinter.Release().
Do you speak russian?:)
- Ivan - Tracker Software
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
- Contact:
- Ivan - Tracker Software
- Site Admin
- Posts: 3550
- Joined: Thu Jul 08, 2004 10:36 pm
- Location: Vancouver Island - Canada
- Contact: