Click here to Skip to main content
15,914,642 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: regd Standard template library in C++ Pin
karteek15-Dec-03 20:38
karteek15-Dec-03 20:38 
GeneralRe: regd Standard template library in C++ Pin
jhwurmbach15-Dec-03 20:42
jhwurmbach15-Dec-03 20:42 
Generalverbs and shared menus in Active x Control Pin
safee ullah15-Dec-03 19:23
safee ullah15-Dec-03 19:23 
GeneralChaging Characters; Pin
Bo Hunter15-Dec-03 18:51
Bo Hunter15-Dec-03 18:51 
GeneralRe: Chaging Characters; Pin
Prakash Nadar15-Dec-03 19:36
Prakash Nadar15-Dec-03 19:36 
GeneralRe: Chaging Characters; Pin
Bo Hunter15-Dec-03 19:50
Bo Hunter15-Dec-03 19:50 
GeneralRe: Chaging Characters; Pin
jhwurmbach15-Dec-03 20:26
jhwurmbach15-Dec-03 20:26 
GeneralGetPrinter return incorrect info about SharedPrinter. Pin
Anonymous15-Dec-03 18:50
Anonymous15-Dec-03 18:50 
hi!
i'm trying to get the number of jobs that in queue of a shared printer.
i used the code that shows in the MSDN:
<br />
BOOL GetJobs(HANDLE hPrinter,        /* Handle to the printer. */ JOB_INFO_2 **ppJobInfo, /* Pointer to be filled.  */<br />
             int *pcJobs,            /* Count of jobs filled.  */ DWORD *pStatus)         /* Print Queue status.    */<br />
{   <br />
	DWORD               cByteNeeded,<br />
                        nReturned,<br />
                        cByteUsed;<br />
<br />
    JOB_INFO_2          *pJobStorage = NULL;<br />
    PRINTER_INFO_2       *pPrinterInfo = NULL;   /* Get the buffer size needed. */ <br />
<br />
	if (!GetPrinter(hPrinter, 2, NULL, 0, &cByteNeeded))<br />
	{<br />
		if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)<br />
			return FALSE;<br />
	}       <br />
	pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);<br />
	if (!(pPrinterInfo))<br />
		/* Failure to allocate memory. */ <br />
		return FALSE;       /* Get the printer information. */ <br />
	if  (!GetPrinter(hPrinter,2,(LPBYTE)pPrinterInfo,cByte<br />
Needed,&cByteUsed))<br />
	{<br />
        /* Failure to access the printer. */ <br />
        free(pPrinterInfo);<br />
        pPrinterInfo = NULL;<br />
        return FALSE;<br />
    }       /* Get job storage space. */<br />
	TRACE("NUM OF PRINT JOBS: %d\n",pPrinterInfo->cJobs);<br />
	if (!EnumJobs(hPrinter,0,pPrinterInfo->cJobs,2,NULL,0,(LPDWORD)&cByteNeeded,(LPDWORD)&nReturned))<br />
	{<br />
		if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)<br />
		{<br />
			free(pPrinterInfo);<br />
			pPrinterInfo = NULL;<br />
			return FALSE;<br />
		}<br />
	}<br />
	pJobStorage = (JOB_INFO_2 *)malloc(cByteNeeded);<br />
	if (!pJobStorage)<br />
	{<br />
		/* Failure to allocate Job storage space. */ <br />
		free(pPrinterInfo);<br />
		pPrinterInfo = NULL;<br />
		return FALSE;<br />
	}<br />
	ZeroMemory(pJobStorage, cByteNeeded);       /* Get the list of jobs. */ <br />
	if (!EnumJobs(hPrinter,0,pPrinterInfo->cJobs,2,(LPBYTE)pJobStorage,cByteNeeded,(LPDWORD)&cByteUsed,(LPDWORD)&nReturned))<br />
	{<br />
		free(pPrinterInfo);<br />
		free(pJobStorage);<br />
		pJobStorage = NULL;<br />
		pPrinterInfo = NULL;<br />
		return FALSE;<br />
	}       /*<br />
        *  Return the information.<br />
        */ <br />
    *pcJobs = nReturned;<br />
    *pStatus = pPrinterInfo->Status;<br />
    *ppJobInfo = pJobStorage;<br />
    free(pPrinterInfo);<br />
	return TRUE;   <br />
}<br />

This code returns the number of jobs, and a pointer to JOB_INFO_2 struct.
i'm using this code to clear the queue list of the printer:
<br />
JOB_INFO_2* jobs;<br />
int noj;<br />
DWORD status;<br />
BOOL err=false;<br />
if (err=GetJobs(hPrinter, &jobs, &noj, &status))<br />
{<br />
	for (int j=0;j<(int)noj;j++)<br />
	{<br />
		SetJob(hPrinter, jobs[j].JobId, 0, NULL, JOB_CONTROL_DELETE);<br />
	}<br />
	free(jobs);<br />
}<br />

but if this printer is a shared printer (from another computer), some times i get num of jobs = 0, and some times the correct one.
most of the times, if i'm F11ing (stepping into) the GetJobs function it works, but if i just do F10 it returns num of jobs = 0. i tried to move the little yellow arrow (in VC++ .net) to the command and do it again, and after 2-3 times it return the correct num of jobs...

Is it a RPC error?

What can i do?!
thanks,
InfraRed
Generalregd CList Pin
karteek15-Dec-03 18:49
karteek15-Dec-03 18:49 
GeneralRe: regd CList Pin
Prakash Nadar15-Dec-03 19:41
Prakash Nadar15-Dec-03 19:41 
GeneralRe: regd CList Pin
karteek15-Dec-03 20:40
karteek15-Dec-03 20:40 
GeneralRe: regd CList Pin
Prakash Nadar15-Dec-03 23:06
Prakash Nadar15-Dec-03 23:06 
GeneralRe: regd CList Pin
David Crow16-Dec-03 4:30
David Crow16-Dec-03 4:30 
GeneralHandling keyboard events in CDialog Pin
suneetchandok15-Dec-03 18:44
susssuneetchandok15-Dec-03 18:44 
GeneralRe: Handling keyboard events in CDialog Pin
Anthony_Yio15-Dec-03 23:15
Anthony_Yio15-Dec-03 23:15 
GeneralCustom error messages in IE Pin
Vermithrax15-Dec-03 11:15
Vermithrax15-Dec-03 11:15 
GeneralJust for sh*ts &amp; giggles... Pin
Shog915-Dec-03 17:21
sitebuilderShog915-Dec-03 17:21 
GeneralRe: Just for sh*ts &amp; giggles... Pin
Vermithrax15-Dec-03 18:14
Vermithrax15-Dec-03 18:14 
GeneralRe: Just for sh*ts &amp; giggles... Pin
Shog915-Dec-03 18:24
sitebuilderShog915-Dec-03 18:24 
GeneralRe: Just for sh*ts &amp; giggles... Pin
Vermithrax15-Dec-03 18:27
Vermithrax15-Dec-03 18:27 
GeneralHaven't tried it myself, but... Pin
Shog915-Dec-03 18:29
sitebuilderShog915-Dec-03 18:29 
GeneralRe: Haven't tried it myself, but... Pin
Vermithrax15-Dec-03 18:34
Vermithrax15-Dec-03 18:34 
GeneralRe: Just for sh*ts & giggles... Pin
Vermithrax15-Dec-03 18:31
Vermithrax15-Dec-03 18:31 
GeneralRe: Just for sh*ts &amp; giggles... Pin
Vermithrax15-Dec-03 18:51
Vermithrax15-Dec-03 18:51 
GeneralRe: Just for sh*ts &amp; giggles... Pin
Shog915-Dec-03 19:23
sitebuilderShog915-Dec-03 19:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.