Board index » cppbuilder » 'No default printer currently selected' error

'No default printer currently selected' error

When a customer using our software tries to print he gets the error
"There is no default printer currently selected"

There are installed printers and one of the printers is set to default. The
customer has Win98 on the client machines and is running Novell Network
Client 3.31 with SP1.

In an attempt to solve the problem I put together a simple console test
application. The test fails if an attempt is made to change
TPrinter::PrinterIndex (to any value including -1). I have pinned down the
problem to the function SetToDefaultPrinter() in printers.pas. It fails
after the second EnumPrinters call, when StructCnt > 0 and 'Device' is
assigned the printer name string. I have put in write statements to trace
execution. Outputting the char array 'Device' throws the NoDefaultPrinter
exception. Printers.pas snippet included for reference below.

I have searched the newsgroups and the error is mentioned about 20 times in
the last five years, but no solutions AFAIK apart from one. One guy removed
IBM AS/400 Client Acess software he had installed and the problem went away.

If anyone has a solution please advise. Thanks

----------------------------------------------------------------------------
--------
procedure TPrinter.SetToDefaultPrinter;
var
  I: Integer;
  ByteCnt, StructCnt: DWORD;
  DefaultPrinter: array[0..1023] of Char;
  Cur, Device: PChar;
  PrinterInfo: PPrinterInfo5;
begin
  ByteCnt := 0;
  StructCnt := 0;
  if not EnumPrinters(PRINTER_ENUM_DEFAULT, nil, 5, nil, 0, ByteCnt,
    StructCnt) and (GetLastError <> ERROR_INSUFFICIENT_BUFFER) then
  begin
    // With no printers installed, Win95/98 fails above with "Invalid
filename".
    // NT succeeds and returns a StructCnt of zero.
    if GetLastError = ERROR_INVALID_NAME then
      RaiseError(SNoDefaultPrinter)
    else
      RaiseLastOSError;
  end;
  PrinterInfo := AllocMem(ByteCnt);
  try
    EnumPrinters(PRINTER_ENUM_DEFAULT, nil, 5, PrinterInfo, ByteCnt,
ByteCnt,
      StructCnt);
    if StructCnt > 0 then
      Device := PrinterInfo.pPrinterName
[snip]

 

Re:'No default printer currently selected' error


I'm somewhat new to Windows and I haven't used Pascal for
decades so I can't comment on how to solve your problem but I
can offer an alternative. The sample that I've included has
been used on several networking environments including
Novell/SPX and it works without any problems. It's part of a
custom dialog that allows the user to send the printed output
to any printer that has been installed on the client but it
doesn't verify that the installed printer actually exists. I
handle that when actually attempting to print. The code is in
C++ but it's so simple that you should be able to easily
convert it.

I hope that it helps. Good Luck

Robert

void __fastcall TForm1::FormActivate(TObject *Sender)
{
CurrentPrinter = Printer()->PrinterIndex;       //Global variable
prnList->Items->Assign(Printer()->Printers);    //ComboBox style = dropdownlist

Quote
}

void __fastcall TForm1::FormDeactivate(TObject *Sender)
{
prnList->Clear();
Printer()->PrinterIndex = CurrentPrinter;

Quote
}

void __fastcall TForm1::prnListChange(TObject *Sender)
{
Printer()->PrinterIndex = Printer()->Printers->IndexOf(prnList->Text);
Quote
}

Re:'No default printer currently selected' error


Hi,

I have also got a few customers reporting problems with this while
using Novell 6 with iPrint (with Delphi 4 application)

Have you found any solution/workaround so far?

Quote
"Simon Hooper" <simon.hoo...@NOSPAM.co.uk> wrote in message <news:3db01383@newsgroups.borland.com>...
> When a customer using our software tries to print he gets the error
> "There is no default printer currently selected"

> There are installed printers and one of the printers is set to default. The
> customer has Win98 on the client machines and is running Novell Network
> Client 3.31 with SP1.

> In an attempt to solve the problem I put together a simple console test
> application. The test fails if an attempt is made to change
> TPrinter::PrinterIndex (to any value including -1). I have pinned down the
> problem to the function SetToDefaultPrinter() in printers.pas. It fails
> after the second EnumPrinters call, when StructCnt > 0 and 'Device' is
> assigned the printer name string. I have put in write statements to trace
> execution. Outputting the char array 'Device' throws the NoDefaultPrinter
> exception. Printers.pas snippet included for reference below.

> I have searched the newsgroups and the error is mentioned about 20 times in
> the last five years, but no solutions AFAIK apart from one. One guy removed
> IBM AS/400 Client Acess software he had installed and the problem went away.

> If anyone has a solution please advise. Thanks

> ----------------------------------------------------------------------------
> --------
> procedure TPrinter.SetToDefaultPrinter;
> var
>   I: Integer;
>   ByteCnt, StructCnt: DWORD;
>   DefaultPrinter: array[0..1023] of Char;
>   Cur, Device: PChar;
>   PrinterInfo: PPrinterInfo5;
> begin
>   ByteCnt := 0;
>   StructCnt := 0;
>   if not EnumPrinters(PRINTER_ENUM_DEFAULT, nil, 5, nil, 0, ByteCnt,
>     StructCnt) and (GetLastError <> ERROR_INSUFFICIENT_BUFFER) then
>   begin
>     // With no printers installed, Win95/98 fails above with "Invalid
> filename".
>     // NT succeeds and returns a StructCnt of zero.
>     if GetLastError = ERROR_INVALID_NAME then
>       RaiseError(SNoDefaultPrinter)
>     else
>       RaiseLastOSError;
>   end;
>   PrinterInfo := AllocMem(ByteCnt);
>   try
>     EnumPrinters(PRINTER_ENUM_DEFAULT, nil, 5, PrinterInfo, ByteCnt,
> ByteCnt,
>       StructCnt);
>     if StructCnt > 0 then
>       Device := PrinterInfo.pPrinterName
> [snip]

Other Threads