Link to home
Start Free TrialLog in
Avatar of swig
swig

asked on

Setting the desired printer (Easy)

I sometimes need to change the default printer.  I am using the SetPrinter procedure but am not getting any results.  I look in the printer setup dialog and see that it is set, but it does not print there.  Help.
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of swig
swig

ASKER

I am unfamiliar with PPrinterInfo2.  Could you explain?
type
  TPrinterInfo2 = record
    pServerName: PAnsiChar;
    pPrinterName: PAnsiChar;
    pShareName: PAnsiChar;
    pPortName: PAnsiChar;
    pDriverName: PAnsiChar;
    pComment: PAnsiChar;
    pLocation: PAnsiChar;
    pDevMode: PDeviceModeA;
    pSepFile: PAnsiChar;
    pPrintProcessor: PAnsiChar;
    pDatatype: PAnsiChar;
    pParameters: PAnsiChar;
    pSecurityDescriptor: PSecurityDescriptor;
    Attributes: DWORD;
    Priority: DWORD;
    DefaultPriority: DWORD;
    StartTime: DWORD;
    UntilTime: DWORD;
    Status: DWORD;
    cJobs: DWORD;
    AveragePPM: DWORD;
  end;

I'm doing this:
(1) Opening the printer.
(2) Getting the size of the PPrinterInfo2, that is needed (the strings are stored behind the structure, so the allocated buffer must be bigger than just the buffer size.
(3) Get the buffer (including the strings).
(4) Now I have the current printer settings.
(5) Change the attributes, so that this printer is the default printer now.
(6) Set the buffer.
(7) Free the buffer.
(8) Close the printer.

Everything clear now?

Regards, Madshi.