Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Mar : Getting a list of network printers

www.cryer.info
Managed Newsgroup Archive

Getting a list of network printers

Subject:Getting a list of network printers
Posted by:"Colin Briede" (crbrie..@iinet.net.au)
Date:Wed, 30 Mar 2005 12:53:12

I am trying to get a list of printers from a network. I am using
enumprinters with PRINTER_ENUM_NAME so I can point to the print server from
which I want to get the list. This works fine on my local PC and a home
network with 2 computers, but it only returns local printers on a large
network. What am I doing wrong???

  EnumPrinters(PRINTER_ENUM_NAME, // types of printer objects to enumerate
               nil,                // name of printer object
               1,                // specifies type of printer info structure
               nil,         // pointer to buffer to receive printer info
structures
               0,                // we use 0 so that Windows tells us how
big a buffer it wants
               pcbNeeded,          // pointer to variable with no. of bytes
copied (or required)
               pcReturned          // pointer to variable with no. of
printer info. structures copied
   );
  GetMem(pBuffer,pcbNeeded);       //create a buffer of the required size
  fillchar(pBuffer^,pcbNeeded,0);
  if EnumPrinters(PRINTER_ENUM_NAME, //now we read the printer list
               PANSICHAR(trim(sitesetup.combobox1.Text)), //user input to
point to the print server
               1,
               pBuffer,
               pcbNeeded,          // this is the real size, in bytes, of
buffer
               pcbNeeded,
               pcReturned
   )=False then begin
   end;
//now we copy that part of the buffer that we are interested in to our
array
system.move(pBuffer^,pPrinter,pcReturned*sizeof(TPrinterInfo1));
  for l:= 0 to pcReturned - 1 do
  begin
    PrinterName:= string(pPrinter[l].pnAME);
    sitesetup.listbox1.items.add(PrinterName);//add to list here
  end;

Replies:

www.cryer.info
Managed Newsgroup Archive