Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why EnumPrinter can't enum all printers in my "Printers and Fax" in WinXP?

13 views
Skip to first unread message

Hiu Sing Ngai

unread,
Apr 7, 2002, 1:41:24 PM4/7/02
to
Hello,
I've got a local printer attached in LTP1 and another shared printer
attached in another computer in the same workgroup. I've added that network
printer in my "Printers and Fax". However, I've tried to enum all printers
but can't enum that network printer but only the local printer. I use the
function like this:

DWORD dwNeeded = 0;
DWORD dwReturned = 0;
EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, NULL, 0, &dwNeeded,
&dwReturned);
if (dwNeeded) {
LPPRINTER_INFO_5 ppi = (LPPRINTER_INFO_5)malloc(dwNeeded);
EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, (LPBYTE)ppi, dwNeeded,
&dwNeeded, &dwReturned);
free(dwNeeded);
}

dwReturn = 1
I've also tried different PRINTER_ENUM_XXX flags but still same. Enum
network even return no printer at all.

Do you have any idea?

Thanks,
Hiu Sing Ngai

Jugoslav Dujic

unread,
Apr 9, 2002, 10:22:46 AM4/9/02
to
"Hiu Sing Ngai" <hiu...@hotmail.com> wrote in message
news:8x%r8.15121$7F1...@nwrddc02.gnilink.net...

That whole printer stuff is a bit tricky... no, It's helluva
tricky. PRINTER_ENUM_CONNECTIONS is your friend, but I'm not
sure that it works with level 5. Here's a snippet of my code
which works correctly (I think so):

VERSIONINFO VI;
LPBYTE pPIBuffer;
PRINTER_INFO_4* lpPI4;
PRINTER_INFO_5* lpPI5;
...
GetVersionEx(&VI);
if (VI%dwPlatformId == VER_PLATFORM_WIN32_NT)
{
iFlags = PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL;
iLevel = 4;
iSize = sizeof(PRINTER_INFO_4);
}
else
{
iFlags = PRINTER_ENUM_LOCAL;
iLevel = 5;
iSize = sizeof(PRINTER_INFO_5);
}
nB = 0;
nPrinters = 0;
EnumPrinters(iFlags, NULL, iLevel, NULL, 0, &nB, &nPrinters);

pPIBuffer = new char[nB];
lpPI4 = (PRINTER_INFO_4*)pPIBuffer;
lpPI5 = (PRINTER_INFO_5*)pPIBuffer;

if (EnumPrinters(iFlags, NULL_CHAR, iLevel, pPIBuffer, nB, &nB, &nPrinters)
...


HTH
Jugoslav
___________
www.geocities.com/jdujic


Hiu Sing Ngai

unread,
Apr 11, 2002, 2:48:38 AM4/11/02
to
Hello Jugoslav,
Thank you so much! PRINTER_ENUM_CONNECTIONS is what I want and works
for me.

Hiu Sing Ngai

"Jugoslav Dujic" <jdujic...@uns.ns.ac.yu> wrote in message
news:a8uted$vc87k$1...@ID-106075.news.dfncis.de...

0 new messages