Solved

AddPrinter API function

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now