Solved

How can I use "EnumPrinters" function?

Posted on 2000-03-20
8
489 Views
Last Modified: 2012-05-04
Hi friends,

I've got a problem using EnumPrinters (and behind the scenes EnumJobs). The problem is that, in the explanation of declaration, they an array of PRINT_INFO_2 (or others) is expected as a parameter, but in the declaration itself, an LPBYTE variable is expected ?? how can an LPBYTE variable be used as an array that receives information about the printers??
 This problem is crucial in my project and any kind of help will be appreciated.

Thank you,

Wesam
0
Comment
Question by:_Wesam
  • 4
  • 2
  • 2
8 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 2635398
Hi _Wesam,

do it like this:

call the EnumPrinters() function once with pPrinterEnum arg set to NULL and cbBuf set to 0. Then return value then should be the number of bytes needed to save the info. Then allocate these number of bytes somehow like this:

int num = EnumPrinters(...);// with pointer set to NULL
BYTE* pBuf = new BYTE[num];
DWORD count = 0;
EnumPrinters(..., &count );// with the allocated pointer passed
//now you can cast the pointer to PRINT_INFO_2 pointer
PRINT_INFO_2* pPrintInfo = (PRINT_INFO_2)pBuf;
for ( int i = 0; i < count; i++ )
{
 // acces the PRINT_INFO_2 with pPrintInfo[i] here
}



hope that helps,

ZOPPO
0
 

Accepted Solution

by:
wardkd earned 30 total points
ID: 2635410
Simply use a cast to LPBYTE in the call to EnumPrinters().

0
 

Author Comment

by:_Wesam
ID: 2636257
Thank you all for your help. It worked perfectly.

Wesam
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 31

Expert Comment

by:Zoppo
ID: 2636267
Hi _Wesam,

JFI, do you use more part's from my comment or from wardkd's?

ZOPPO
0
 

Author Comment

by:_Wesam
ID: 2636292
Well, I had to modify your code to get it work, I did what wardkd say. Anyway I wanted to ACCEPT your ANSWER, but the browser showed me only an ACCEPT button to wardkd's answer ????
Thank you for your help,

Wesam.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2636330
Now, listen, you should never accept an answer you did not use!!!

You always have possibility to 'reject' an answer.

It's a matter of fairness to award points to those experts which helped you most ar at least as first.
0
 

Expert Comment

by:wardkd
ID: 2639937
The question was:
"how can an LPBYTE variable be used as an array that receives information about the printers?"

Which I believe I answered correctly.

However, if this is going to cause grief for anyone, I'd rather not take the points.

NOTE: If you want something that you say to be taken as THE ANSWER, then submit an answer!
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2639995
I just think it's a bad habit to answer a question AS ANSWER when other experts already posted senseful comments ... and, I think it's good habit posting even an answer AS COMMENT, because it doesn't lock the question and so doesn't decrease other expert's interest.

BTW, who cares .........
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

770 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