Click to See Complete Forum and Search --> : SetJob Printer API not working


pradip_mondal
January 24th, 2003, 02:18 PM
Hi,
My objective is to send across ASCII text(data picked up from a file) to the Printer in Landscape Mode.
For that i an using the Printing and Print Spooler Functions.
OpenPrinter()
StartDocPrinter()
StartPagePrinter()
GetJob()
SetJob()
WritePrinter()
EndPagePrinter()
EndDocPrinter()
ClosePrinter()

I need to set the PrintJob Orientation using the standard Printing and Print Spooler functions.
I have used the following code.
None of the windows function returns any error code, i.e. SetJob successds. But after that when i retrieve the Job Details using GetJob function, it retrieves the Orientation value as DMORIENT_PORTRAIT.

If anybody has any other suggestions, i mean any other way i can send ASCII data from a file to a printer in Landscape mode is welcome.

Thanks and Regards,
Pradip.

void CMyPS2Dlg::MySetPrinter()
{
HANDLE hPrinter = NULL;
int nRetVal = 0;
int nJobId = 0;
DWORD dwBytesRead = 0;
DWORD dwBytesWritten = 0;
char cBuffer[BUFFER_DATA_SIZE];
DWORD dwNeeded = 0;
DWORD dwRet = 0;
JOB_INFO_2 *pd_JobInfo = NULL;


PRINTER_DEFAULTS pd;
ZeroMemory(&pd, sizeof(pd));

pd.DesiredAccess = PRINTER_ACCESS_USE;
pd.pDatatype = "RAW";
pd.pDevMode = NULL;

nRetVal = 0;
nRetVal = OpenPrinter("lpsiips", &hPrinter, &pd);
nRetVal = GetLastError();

DOC_INFO_1 dInfo;
dInfo.pDatatype = "RAW";
dInfo.pDocName = "something";
dInfo.pOutputFile = NULL;

nRetVal = 0;
nJobId = StartDocPrinter(hPrinter, 1, (LPBYTE)&dInfo);
nRetVal = GetLastError();

nRetVal = 0;
nRetVal = StartPagePrinter(hPrinter);
nRetVal = GetLastError();



nRetVal = 0;
nRetVal = GetJob( hPrinter, nJobId, 2, (LPBYTE)pd_JobInfo , NULL, &dwNeeded);
nRetVal = GetLastError();

if (nRetVal != ERROR_INSUFFICIENT_BUFFER)
return;
pd_JobInfo = (JOB_INFO_2 *)malloc(dwNeeded);

if(NULL == pd_JobInfo)
return;

nRetVal = 0;
nRetVal = GetJob( hPrinter, nJobId, 2, (LPBYTE)pd_JobInfo , dwNeeded , &dwRet);
nRetVal = GetLastError();

if (pd_JobInfo->pDevMode->dmFields & DM_ORIENTATION)
{
pd_JobInfo->pDevMode->dmOrientation = DMORIENT_LANDSCAPE;//DMORIENT_PORTRAIT; //DMORIENT_LANDSCAPE;
}
else
{
return;
}

pd_JobInfo->Position = JOB_POSITION_UNSPECIFIED;

nRetVal = 0;
nRetVal = SetJob(hPrinter, nJobId, 2, (LPBYTE)pd_JobInfo,0);
nRetVal = GetLastError();


strcpy(cBuffer, "what the ****");

nRetVal = 0;
nRetVal = WritePrinter(hPrinter, cBuffer, sizeof(cBuffer), &dwBytesWritten) ;
nRetVal = GetLastError();


nRetVal = 0;
nRetVal = GetJob( hPrinter, nJobId, 2, (LPBYTE)pd_JobInfo , NULL, &dwNeeded);
nRetVal = GetLastError();

if (nRetVal != ERROR_INSUFFICIENT_BUFFER)
return;

if(pd_JobInfo)
{
free(pd_JobInfo);
pd_JobInfo = NULL;
}
pd_JobInfo = (JOB_INFO_2 *)malloc(dwNeeded);

if(NULL == pd_JobInfo)
return;

nRetVal = 0;
nRetVal = GetJob( hPrinter, nJobId, 2, (LPBYTE)pd_JobInfo , dwNeeded , &dwRet);
nRetVal = GetLastError();

if(NULL != hPrinter)
EndPagePrinter(hPrinter);

if(NULL != hPrinter)
EndDocPrinter(hPrinter);

if(NULL != hPrinter)
ClosePrinter(hPrinter);

return;
}