Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

EnumJobs

Posted on 1999-07-06
17
Medium Priority
?
378 Views
Last Modified: 2008-03-17
I am using EnumJobs to enumerate all the print jobs in the print queue. It is returning JOB_INFO_2 structures.

Now,

In the JOB_INFO_2 there is a pointer to a DEVMODE structure that is suppose to be returned but it is not being returned!

please help,

I need this pointer to be returned!
0
Comment
Question by:kennym141282
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 3
17 Comments
 
LVL 1

Expert Comment

by:BSoeters
ID: 1199216
Could you post the portion of your code which is misbehaving ?

0
 

Author Comment

by:kennym141282
ID: 1199217
I will do when I get home :)
0
 
LVL 1

Expert Comment

by:BSoeters
ID: 1199218
That's ok with me :)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:kennym141282
ID: 1199219
JOB_INFO_2 JOBS[100];
DWORD Needed;
DWORD Returned;
HANDLE hPrint;

OpenPrinter("EPSON Stylus Color 600",&hPrint,NULL);
EnumJobs(hPrint,0,-1,2,(unsigned char *)JOBS,sizeof(JOBS),&Needed,&Returned);
0
 
LVL 1

Expert Comment

by:BSoeters
ID: 1199220
The code you posted works just fine.

Indeed, the pointer to devmode is NULL for all the enumerated jobs on the specific printer device.

That's odd. I think this is because of the functionality of EnumJobs(). Probably, the Microsoft people must've thought that EnumJobs() was not required to return a valid devmode pointer too.

I built the following piece of code for correcting that. Please try it out and post your findings.

---[ snip here, c code ]---8<---

DEVMODE *devmode = NULL;

devmode = (DEVMODE*) LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, DocumentProperties (NULL, hPrint, NULL, devmode, NULL, 0));
if (LocalSize (LocalHandle ((void*) devmode)) == DocumentProperties (NULL, hPrint, NULL, devmode, NULL, 0))
   DocumentProperties (NULL, hPrint, NULL, devmode, NULL, DM_OUT_BUFFER);

/* devmode points to valid DEVMODE structure here ! */

devmode = (DEVMODE*) LocalFree (LocalHandle ((void*) devmode));

/* devmode is invalid here ! do not use ! */

---[ snip here, c code ]--->8---

Remember to put it just behind your code, when you've opened a particular printing device using OpenPrinter() and acquired a valid printer handle by doing so.

Another piece of code, using the C++ new operator instead of the Win32 API function LocalAlloc():

---[ snip here, c++ code ]---8<---

DEVMODE *devmode = NULL;

if (devmode = (DEVMODE*) new char [DocumentProperties (NULL, hPrint, NULL, devmode, NULL, 0)])
   DocumentProperties (NULL, hPrint, NULL, devmode, NULL, DM_OUT_BUFFER);

/* devmode points to valid DEVMODE structure here ! */

if (devmode)
   {
   delete devmode;
   devmode = NULL;
   }

/* devmode is invalid here ! do not use ! */

---[ snip here, c++ code ]--->8---

I hope this helps you out. I still find it odd, that EnumJobs() doesn't return any DEVMODE data.

Good luck !

By the way, if I may ask, what are you building ?
0
 

Author Comment

by:kennym141282
ID: 1199221
A printer credits program...

the DEVMODE structure has some info I need to calculate the credits needed :)
0
 
LVL 1

Expert Comment

by:BSoeters
ID: 1199222
Nice, a printer credits program. We use that in school too, for subtracting credits from students accounts. Too bad they always print one banner page with it, always loosing one credit (1 credit == 1 page) :(

Did you try the piece of code I posted ? It should work, it went trough some extensive testing ;)

It still puzzles me why EnumJobs does not return devmode data anyway...
0
 

Author Comment

by:kennym141282
ID: 1199223
Does this get the DEVMODE of a job in the printer queue that is waiting and not being printed?
0
 
LVL 1

Expert Comment

by:BSoeters
ID: 1199224
No, that's the problem. I don't know why EnumJobs is not returning any DEVMODE data.

The only way I could come up with DEVMODE data was like this. Although it's not a per document DEVMODE.
0
 
LVL 1

Expert Comment

by:BSoeters
ID: 1199225
Is this statisfactory for you ?
0
 

Author Comment

by:kennym141282
ID: 1199226
Not really.... :( sorry, but I really need it by job
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 200 total points
ID: 1199227
I recoment you for getting DEVMODE information use
GetPrinter API.
Code may be as this: (tested with BC 5.01)
BOOL TestDevMode(void)
{
  HANDLE hPrinter = NULL;
  DWORD cByteNeeded,nReturned,cByteUsed;
  PRINTER_DEFAULTS pd;
  PRINTER_INFO_2 *pPrinterInfo = NULL;

  ZeroMemory(&pd, sizeof(pd));

  OpenPrinter("EPSON Stylus COLOR 600",&hPrinter,&pd);
             /* Get the buffer size needed. */
  if (!GetPrinter(hPrinter, 2, NULL, 0, &cByteNeeded))
     {
       if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
         return FALSE;
     }
  pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);
  if (!(pPrinterInfo))           /* Failure to allocate memory. */
     return FALSE;       /* Get the printer information. */
  if (!GetPrinter(hPrinter,2,(LPSTR)pPrinterInfo,
                  cByteNeeded,&cByteUsed))
     {
           /* Failure to access the printer. */
        free(pPrinterInfo);
        pPrinterInfo = NULL;
        return FALSE;
     }
      //in this moment in pPrinterInfo.pDevMode DEVMODE   structure
   ...... //you code

  free (pPrinterInfo);
  ClosePrinter(hPrint);
  return TRUE;
}
Good Luck, Alex
0
 

Author Comment

by:kennym141282
ID: 1199228
will this get the DEVMODE structure for jobs in the queue?
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1199229
Hi, i have only bad news for you.
I test EnumJobs, and this one don't return DEVMODE structure...
Why? Only MicroSoft knows... Next programm tests this thing:

BOOL GetJobs(HANDLE hPrinter,        /* Handle to the printer. */
             int *pcJobs,            /* Count of jobs filled.  */
             DWORD *pStatus)         /* Print Queue status.    */
{
   DWORD cByteNeeded,nReturned,cByteUsed;
   JOB_INFO_2     *pJobStorage;
   PRINTER_INFO_2 *pPrinterInfo;
             /* Get the buffer size needed. */
   if (!GetPrinter(hPrinter, 2, NULL, 0, &cByteNeeded))
     {
       if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
         return FALSE;
     }
   pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);
   if (!(pPrinterInfo))           /* Failure to allocate memory. */
     return FALSE;       /* Get the printer information. */
   if (!GetPrinter(hPrinter,2,(LPBYTE)pPrinterInfo,
                  cByteNeeded,&cByteUsed))
     {
           /* Failure to access the printer. */
        free(pPrinterInfo);
        return FALSE;
     }
       /* Get job storage space. */   /*pPrinterInfo->cJobs*/
   if (!EnumJobs(hPrinter,0,pPrinterInfo->cJobs,2,
                 NULL,0,(LPDWORD)&cByteNeeded,
               (LPDWORD)&nReturned))
     {
       if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
         {
           free(pPrinterInfo);
           return FALSE;
         }
     }
   if (cByteNeeded > 0)      //there are jobs!
     {
       pJobStorage = (JOB_INFO_2 *)malloc(cByteNeeded);
       if (!pJobStorage)
         {           /* Failure to allocate Job storage space. */
           free(pPrinterInfo);
           return FALSE;
         }
       ZeroMemory(pJobStorage, cByteNeeded);
       /* Get the list of jobs. */
       if (!EnumJobs(hPrinter,0l,pPrinterInfo->cJobs,2l,
              (LPBYTE)pJobStorage,cByteNeeded,
              (LPDWORD)&cByteUsed,(LPDWORD)&nReturned))
         {
           free(pPrinterInfo);
           free(pJobStorage);
           return FALSE;
         }
       for (int i = 0; i < nReturned; i++)
         {  /* Return the information. for some job*/
           JOB_INFO_2 *jobInfo  = pJobStorage+i;
           DEVMODE *pDev = jobInfo->pDevMode; //allways NULL!
         }
       free(pJobStorage );
     }
   *pcJobs = nReturned;
   *pStatus = pPrinterInfo->Status;
   free(pPrinterInfo);
   return TRUE;
}
Use GetPrinter, as I point out in the Reply, it works!
Good Luck, Alex
0
 
LVL 1

Expert Comment

by:BSoeters
ID: 1199230
Alex, how can you even think that posting the same unstatisfying answer I gave will help kennym141282 out ?
0
 
LVL 1

Expert Comment

by:BSoeters
ID: 1199231
Kenny, maybe someone else has a clue about why EnumJobs does not return DEVMODE structure pointers...

That's the only problem here
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1199232
to BSoeters: i can't tell about Kenny, but exist what
exist. About why is: i thing this depends from Printer
Driver. can be You Printer Driver retrieve this information, but my Epson/HP not! In every case, if some
drivers not retrive DEVMODE, you can't builde you
programme on this. Again: Real answer: using GetPrinter!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question