Hello, I have an inquiry in the process of printing the printer.
Below are three of my program descriptions.
[My Application info]
- Hook the APIs related to printing, such as StartDoc, StartPage, ExtTextOut, EndPage, and EndDoc.
- After checking the entire string obtained from ExtTextOut in EndDoc API during printing, when a specific string is detected, the printer is deleted and the approval page is viewed.
- After receiving approval, I would like to reprint the existing printer.
(JOB_CONTROL_RESUME will not be used in my program. You must print again after deleting unconditionally.)
- Don't show the dialog again when reprinting.
With all the property information of the print that was started at the beginning in the DocumentProperties API, the same print is restarted with that information.
[Current Re-Print Logic]
This is my current status.
If you delete Print and proceed with printing again (this is the logic to run StartDoc, StartPage, Endpage, EndDoc that was previously in progress after creating a new printer DC), in a specific document (textbox of Excel, etc.), normal output is not possible.
I checked MSDN and it was confirmed that there is no API to output a specific print name in Windows, so I wrote the code as above.
[PowerShell Command]
Also, for printing, I tried the following command using PowerShell to print several files (ppt, xls, doc ...etc) including txt files.
PowerShell > Start-Process -FilePath "C:\Users\DeveloperO\Desktop\1234.docx" -Verb print
The above command worked, but the result is not what I want because a new process has been started.
Starting a new process and starting a print doesn't work for me.
[Please Answer]
Question 0)
Is there a command to print an open process without starting the process using powershell?
(Currently, I know that only txt files can be printed.)
Question 1)
I've been working in C++ language, is there an API to programmatically request a printer using C++?
Question 2)
I've also tried the ScheduleJob API. But this keeps giving 3002 Error. (Cannot find spool file.)
The code for this is below, can you give me some advice?
////////////////////////////////////////
/////////ScheduleJob Code//////////
////////////////////////////////////////
BOOL bResult = FALSE;
HANDLE hPrinter = NULL;
DWORD dNeedNum = 0;
CHAR szFullPath[MAX_PATH] = {0,};
DWORD size = 4096;
ADDJOB_INFO_1 * JobInfo = {0,};
W2M(g_wszFullPath, szFullPath);
bResult = OpenPrinter("Printer Name", &hPrinter, NULL );
if(bResult == FALSE)
{
printf("Error = %d",GetLastError());
}
JobInfo=(ADDJOB_INFO_1 *)LocalAlloc((LMEM_FIXED/LMEM_ZEROINIT),size);
bResult = AddJob(hPrinter,1,(BYTE *)JobInfo,size,&dNeedNum);
if(bResult == FALSE)
{
printf("Error = %d",GetLastError());
}
ZeroMemory(JobInfo->Path, sizeof(JobInfo->Path));
StringCbCopy(JobInfo->Path, sizeof(szFullPath), szFullPath);
bResult = ScheduleJob(hPrinter,JobInfo->JobId);
if(bResult == FALSE)
{
printf("Error = %d",GetLastError()); // <- Error Point 3002 Error
}
LocalFree(JobInfo);
ClosePrinter(hPrinter);