Solved

AddPrinter API function

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert MS Word document to a PDF file 9 115
Delphi and Access based Enumeration 9 78
how to change, disabled button color FMX ? 1 51
firemonkey Android Listview Sort items 7 73
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

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