Solved

AddPrinter API function

Posted on 2001-09-14
4
1,558 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

726 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