N
NickP
Hi there,
How would I wait until the Word document has finished printing to file?
I have tried several attempts so far, firstly to monitor the printer in
question to wait for the state to change from Busy, and secondly to monitor
to file for the lock to be released. Both of which are unsuccessful as it
locks the thread that is currently attempting to Print. This suggests to be
that even though Word returns the second the document starts to print or
fails, it is not truely asynchronous.
I have code working via VB.NET that just monitors the lock on the file,
and this works fine, but not in the case of C++.
Any ideas on how to handle this? I need my function to only return once
the document has printed successfully.
.....
if(S_OK==pDPrDocument->PrintOut(&vtMissing, &pVarAppend, &vtMissing,
&pVarOutputFileName, &vtMissing, &vtMissing, &vtMissing, &vtMissing,
&vtMissing, &vtMissing, &pVarPrintToFile))
{
bool pBlnBusy = true;
HANDLE pHanPrinter = NULL;
if(OpenPrinter(_T("<name of printer here>"), &pHanPrinter, NULL))
{
while(pBlnBusy)
{
Sleep(100);
DWORD pDWdSize;
GetPrinter(pHanPrinter, 6, NULL, NULL, &pDWdSize);
PRINTER_INFO_6* pPIoStatus = (PRINTER_INFO_6 *)GlobalAlloc(GPTR,
pDWdSize);
GetPrinter(pHanPrinter, 6, (LPBYTE)pPIoStatus, pDWdSize,
&pDWdSize);
bool pBlnBusyTemp = false;
int pIntCurInfo;
for(pIntCurInfo=0;pIntCurInfo!=pDWdSize;pIntCurInfo++)
{
if(pPIoStatus[pIntCurInfo].dwStatus)
pBlnBusyTemp = true;
}
if(!pBlnBusyTemp) pBlnBusy = false;
}
ClosePrinter(pHanPrinter);
}
}
.....
Unfortunately the above still locks the thread that is attempting to
print. Even throwing in a messagebox doesn't help.
Thanks a million in advance.
Nick.
How would I wait until the Word document has finished printing to file?
I have tried several attempts so far, firstly to monitor the printer in
question to wait for the state to change from Busy, and secondly to monitor
to file for the lock to be released. Both of which are unsuccessful as it
locks the thread that is currently attempting to Print. This suggests to be
that even though Word returns the second the document starts to print or
fails, it is not truely asynchronous.
I have code working via VB.NET that just monitors the lock on the file,
and this works fine, but not in the case of C++.
Any ideas on how to handle this? I need my function to only return once
the document has printed successfully.
.....
if(S_OK==pDPrDocument->PrintOut(&vtMissing, &pVarAppend, &vtMissing,
&pVarOutputFileName, &vtMissing, &vtMissing, &vtMissing, &vtMissing,
&vtMissing, &vtMissing, &pVarPrintToFile))
{
bool pBlnBusy = true;
HANDLE pHanPrinter = NULL;
if(OpenPrinter(_T("<name of printer here>"), &pHanPrinter, NULL))
{
while(pBlnBusy)
{
Sleep(100);
DWORD pDWdSize;
GetPrinter(pHanPrinter, 6, NULL, NULL, &pDWdSize);
PRINTER_INFO_6* pPIoStatus = (PRINTER_INFO_6 *)GlobalAlloc(GPTR,
pDWdSize);
GetPrinter(pHanPrinter, 6, (LPBYTE)pPIoStatus, pDWdSize,
&pDWdSize);
bool pBlnBusyTemp = false;
int pIntCurInfo;
for(pIntCurInfo=0;pIntCurInfo!=pDWdSize;pIntCurInfo++)
{
if(pPIoStatus[pIntCurInfo].dwStatus)
pBlnBusyTemp = true;
}
if(!pBlnBusyTemp) pBlnBusy = false;
}
ClosePrinter(pHanPrinter);
}
}
.....
Unfortunately the above still locks the thread that is attempting to
print. Even throwing in a messagebox doesn't help.
Thanks a million in advance.
Nick.