'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]