Solved

AddPrinter API function

Posted on 2001-09-14
4
1,541 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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