Solved

AddPrinter API function

Posted on 2001-09-14
4
1,546 Views
Last Modified: 2012-06-27
Does anyone know how to use this function in Delphi, how i can setup a printer with this function?

Palli
0
Comment
Question by:palli011000
  • 2
4 Comments
 
LVL 1

Expert Comment

by:vterekh
ID: 6482601
Hi Palli

This question was being discussed there. Take a look to the next topics:

http://www.experts-exchange.com/jsp/qShow.jsp?qid=20101017

Regards.
Vasily
0
 
LVL 21

Accepted Solution

by:
gemarti earned 100 total points
ID: 6484568
Here is an example I am working on: It is not fully tested and you'll have to get the information for the printer drivers that you intend to install. This is for a network installation from a NT print server to a local W9x machine:


-------------cut below line -------------------------------

unit Cntprints;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Winspool;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  hPrinter : HWND;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  pLevel,dLevel : Cardinal;
  cbBuf: Cardinal;
  phPrinter : Cardinal;
  hPrinter : HWND;
  pcbNeeded: Cardinal;
  pDefault : PPrinterDefaultsA;
  pi2 : PRINTER_INFO_2;
  di2 : DRIVER_INFO_3;
begin
  Try
    dLevel := 3; {This value can be either 2 or 3}
    pLevel := 2; {This value must be 2}
    cbBuf := SizeOf(DRIVER_INFO_3);
    pDefault.pDatatype := pi2.pDatatype;
    pDefault.pDevMode := pi2.pDevMode;
    pDefault.DesiredAccess := PRINTER_ACCESS_ADMINISTER;
    //pDefault.DesiredAccess := PRINTER_ACCESS_USE;

    ZeroMemory(@pi2,SizeOf(PRINTER_INFO_2));
    {Di351 PCL6 Printer Information}
    pi2.pServerName := '\\server1';
    pi2.pComment := 'ACCTP2b Minolta Di351 PCL6';
    pi2.pLocation := 'Building 2 Copier Room';
    pi2.pPrinterName := '\\server1\ACCTP2b';
    pi2.pPortName := '\\server1\acctp2b';
    pi2.pDriverName := 'Minolta Di351 PCL6';
    pi2.pPrintProcessor := 'WinPrint';

    zeroMemory(@di2,SizeOf(Driver_INFO_3));
    {Di351 PCL6 Driver Information}
    di2.cVersion := 0;
    di2.pName := 'Minolta Di351/251/200 PCL6';
    di2.pEnvironment := 'Windows 95';
    di2.pDriverPath := 'c:\windows\system\DLSPS95.dll';
    di2.pDataFile := 'c:\windows\system\Minolta Di351U-P5.ppd';
    di2.pConfigFile := 'c:\windows\system\DLSPS95.dll';
    di2.pDependentFiles := 'DLSPS.HLP\DLSPS95.DLL\DLSSTR.dat\MLTDLSPS.DRV\MLTDLSTP.INF\MODEL_IS.INI\Pi3502PS.CAT\0\0';
    di2.pDefaultDataType := 'EMF';

    {You must open the printer before you can do anything with it}

    OpenPrinter(@pi2,phPrinter,@pDefault);
    AddPrinterDriver('',dLevel,pi2.pPrinterName);

    {The handle returned in this function is the handle to the printer}
    hPrinter := AddPrinter('',pLevel,@pi2);

    GetPrinterDriver(hPrinter,di2.pEnvironment,0,@di2,cbBuf,pcbNeeded);
    GetPrinterDriverDirectory(di2.PName,di2.pEnvironment,0,di2.pDriverPath,cbBuf,pcbNeeded);
  finally
    AddPrinter('',pLevel,@pi2);
    ClosePrinter(hPrinter);
  end;
end;

end.
0
 

Author Comment

by:palli011000
ID: 6498484
does it work gemarti?
0
 

Author Comment

by:palli011000
ID: 6513543
Can you asnwer the question i have post?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question